Git Product home page Git Product logo

Comments (5)

1725636955 avatar 1725636955 commented on May 9, 2024

`@Order
@configuration
@ConditionalOnClass(SmartEngine.class)
@slf4j
public class SmartEngineAutoConfiguration implements ApplicationContextAware {

private ApplicationContext applicationContext;

@Bean
@ConditionalOnMissingBean
public SmartEngine constructSmartEngine() {
    ProcessEngineConfiguration processEngineConfiguration = new DefaultProcessEngineConfiguration();

// 自定义处理类获取
processEngineConfiguration.setInstanceAccessor(new CustomInstanceAccessService());

// see https://github.com/alibaba/SmartEngine/wiki/SmartEngine-UserGuide--Chinese-Version-(%E4%B8%AD%E6%96%87%E7%89%88)#usertask
// UserTask是DataBase模式下特有的功能。
// UserTask和TaskAssigneeDispatcher,待办列表(TaskInstance)紧密关联。 通过TaskAssigneeDispatcher,可以实现自动获取某个节点的任务处理者
processEngineConfiguration.setTaskAssigneeDispatcher(new DefaultTaskAssigneeDispatcher());

// 自定义 processInstanceId 生成
processEngineConfiguration.setIdGenerator(new CustomerIdGenerator());

// 自定义锁
processEngineConfiguration.setLockStrategy(new DefaultLockStrategy());

// SimpleAnnotationScanner scanner = new SimpleAnnotationScanner("com.alibaba.smart.framework.engine.persister.database",
// "com.alibaba.smart.framework.engine.service");
// processEngineConfiguration.setAnnotationScanner(scanner);

    SmartEngine smartEngine = new DefaultSmartEngine();
    smartEngine.init(processEngineConfiguration);

    deployProcessDefinition(smartEngine);

    return smartEngine;
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
}

private class CustomInstanceAccessService implements InstanceAccessor {
    @Override
    public Object access(String name) {
        try {
            return applicationContext.getBean(name);
        } catch (BeansException e) {
            log.error("smart engine 获取 bean 异常", e);
            throw e;
        }
    }

}


private void deployProcessDefinition(SmartEngine smartEngine) {
    RepositoryCommandService repositoryCommandService = smartEngine
            .getRepositoryCommandService();

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        Resource[] resources = resolver.getResources("smart-engine/*.xml");
        for (Resource resource : resources) {
            InputStream inputStream = resource.getInputStream();
            repositoryCommandService.deploy(inputStream);
            IOUtil.closeQuietly(inputStream);
        }
    } catch (Exception e) {
        throw new EngineException(e);
    }

}

/**
 * 自定义 processInstanceId 生成
 */
private static class CustomerIdGenerator implements IdGenerator {

    private static final Sequence SEQUENCE = new Sequence(null);

    @Override
    public void generate(Instance instance) {
        instance.setInstanceId(String.valueOf(SEQUENCE.nextId()));
    }
}

}`

from smartengine.

1725636955 avatar 1725636955 commented on May 9, 2024

这是我的配置

from smartengine.

1725636955 avatar 1725636955 commented on May 9, 2024

我理解应该是需要自定义 SimpleAnnotationScanner 的扫描路径,但是不知道需要哪些

from smartengine.

vavi avatar vavi commented on May 9, 2024

目前不能同时在一个应用内部署2种模式

from smartengine.

1725636955 avatar 1725636955 commented on May 9, 2024

目前不能同时在一个应用内部署2种模式

ok

from smartengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.