Comments (16)
@HarisHashim: what an amount of text above here ;-) I'm trying to reconstruct ... do you have a repo with the code in I can take a look at?
These lines:
CustomUserEntityManagerFactory userEntityManagerFactory = new CustomUserEntityManagerFactory();
CustomGroupEntityManagerFactory groupEntityManagerFactory = new CustomGroupEntityManagerFactory();
sessionFactories.put(CustomUserEntityManager.class, userEntityManagerFactory);
sessionFactories.put(CustomGroupEntityManager.class, groupEntityManagerFactory);
should indeed do it.
(For future reference: I added a simpler way to do the above in the current master: https://github.com/Activiti/Activiti/blob/master/modules/activiti-spring-boot/spring-boot-starters/activiti-spring-boot-starter-basic/src/main/java/org/activiti/spring/boot/ProcessEngineConfigurationConfigurer.java)
from spring-boot-with-activiti-example.
@z772458549 ,
i use spring boot, the final config like below.
`@Configuration
@AutoConfigureBefore(org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class)
public class ActivitiConfiguration implements ProcessEngineConfigurationConfigurer {
@Resource(name = "myGroupManagerFactory")
private SessionFactory groupManagerFactory;
@Resource(name = "myUserManagerFactory")
private SessionFactory userManagerFactory;
public void configure(SpringProcessEngineConfiguration pec) {
// 权限设置
pec.setDbIdentityUsed(false); // 禁用activiti默认的权限表
// 替换activiti的默认权限功能
List<SessionFactory> customSessionFactories = new ArrayList<SessionFactory>();
customSessionFactories.add(userManagerFactory);
customSessionFactories.add(groupManagerFactory);
if (pec.getCustomSessionFactories() == null){
pec.setCustomSessionFactories(customSessionFactories);
}
else{
pec.getCustomSessionFactories().addAll(customSessionFactories);
}
}
}`
from spring-boot-with-activiti-example.
The regular Spring way: have a @configuration class and inject the ProcessEngine or ProcessEngineConfiguration bean that is created by Spring Boot.
Alternatively, you can also define the engine/config bean yourself and Spring Boot won't instantiate it for you (at least, that's how I remember it)
from spring-boot-with-activiti-example.
Thanks.
from spring-boot-with-activiti-example.
Hello there, I am trying to do the same. Since I am new to Spring Boot and Activiti, don't really understaood what is meant by
"The regular Spring way: have a @configuration class and inject the ProcessEngine or ProcessEngineConfiguration bean that is created by Spring Boot."
I have (blindly) tried with bellow codes. And get errors (attached at the end). Appreciate anyhelp!
TIA
Haris
@Configuration
public class ProcessEngineConfig {
@Autowired
private ProcessEngineConfiguration processEngineConfiguration;
@Autowired
private CustomUserEntityManagerFactory userEntityManagerFactory;
@Autowired
private CustomGroupEntityManagerFactory groupEntityManagerFactory;
public void configure() {
Map<Class<?>, SessionFactory> sessionFactories = ((ProcessEngineConfigurationImpl) processEngineConfiguration)
.getSessionFactories();
sessionFactories.put(CustomUserEntityManager.class, userEntityManagerFactory);
sessionFactories.put(CustomGroupEntityManager.class, groupEntityManagerFactory);
ProcessEngine engine = processEngineConfiguration.buildProcessEngine();
ProcessEngines.registerProcessEngine(engine);
ProcessEngines.init();
}
}
But I am getting bellow errors
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngineConfig': Injection of autowired dependencies failed;
...
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.CustomUserEntityManagerFactory org.activiti.ProcessEngineConfig.userEntityManagerFactory;
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.activiti.CustomUserEntityManagerFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngineConfig': Injection of autowired dependencies failed
...
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.CustomUserEntityManagerFactory org.activiti.ProcessEngineConfig.userEntityManagerFactory;
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.activiti.CustomUserEntityManagerFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
OR AS ATTACHED
from spring-boot-with-activiti-example.
My bad!
Removed @Autowired from the two custom factory
//@Autowired
private CustomUserEntityManagerFactory userEntityManagerFactory;
//@Autowired
private CustomGroupEntityManagerFactory groupEntityManagerFactory;
Now it builds and run but the configure() function was never run. So obviously this is wrong way to do it.
To be honest I dont understand what is meant by
"The regular Spring way: have a @configuration class and inject the ProcessEngine or ProcessEngineConfiguration bean that is created by Spring Boot."
I tried initializing using constructor and then call configure().
public ProcessEngineConfig() {
userEntityManagerFactory = new CustomUserEntityManagerFactory();
groupEntityManagerFactory = new CustomGroupEntityManagerFactory();
configure();
}
This give me
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.activiti.ProcessEngineConfig$$EnhancerBySpringCGLIB$$99c4af75]: Constructor threw exception; nested exception is java.lang.NullPointerException
i.e. the injected processEngineConfiguration is actually null.
So again appreciate help. @jbarrez
Best Regards,
Haris
from spring-boot-with-activiti-example.
This code build and run without run time error.
Have not tested it to know whether it actually work yet.
@Configuration
public class ActivitiConfig {
@Bean
public ProcessEngine processEngine(ProcessEngineConfigurationImpl pec, ApplicationContext applicationContext) throws Exception {
ProcessEngineFactoryBean pe = new ProcessEngineFactoryBean();
pe.setProcessEngineConfiguration(pec);
pe.setApplicationContext(applicationContext);
return pe.getObject();
}
@Primary
@Bean
public ProcessEngineConfigurationImpl getProcessEngineConfiguration(
DataSource dataSource,
PlatformTransactionManager transactionManager,
ApplicationContext context) {
SpringProcessEngineConfiguration pec = new SpringProcessEngineConfiguration();
pec.setDataSource(dataSource);
pec.setDatabaseSchemaUpdate("true");
pec.setJobExecutorActivate(true);
pec.setHistory("full");
pec.setMailServerPort(2025);
pec.setDatabaseType("h2");
pec.setTransactionManager(transactionManager);
pec.setApplicationContext(context);
Map<Class<?>, SessionFactory> sessionFactories = new HashMap<Class<?>, SessionFactory>();
CustomUserEntityManagerFactory userEntityManagerFactory = new CustomUserEntityManagerFactory();
CustomGroupEntityManagerFactory groupEntityManagerFactory = new CustomGroupEntityManagerFactory();
sessionFactories.put(CustomUserEntityManager.class, userEntityManagerFactory);
sessionFactories.put(CustomGroupEntityManager.class, groupEntityManagerFactory);
pec.setSessionFactories(sessionFactories);
return pec;
}
@Bean
public RuntimeService getRuntimeService(ProcessEngine processEngine) {
return processEngine.getRuntimeService();
}
}
from spring-boot-with-activiti-example.
To some extent I know that above code works. For instance during first test, there is a runtime error but the app keeps running.
They are several errors telling me that during startup the app can not insert stuff into act_id_group table. I double check with previous database and it shows that, indeed some group are created and inserted into that table. This group are created on the fly when process is read into the system. This is indeed true, since I have a process diagram that I assign some task/process to several groups.
Fixing that error in the custom group code, I no longer see same error when running the app. So my conclussion, I fix the error! However, at the same time I did not see the same groups mentioned above being created in act_id_group or my custom group_data table.
I am writing this for the benefit of the next person who discover this thread. If there is answer, that will help a lot. Otherwise, will just keep banging my head on the wall hopping to find solution.
Cheers!
:D
from spring-boot-with-activiti-example.
Nah ... it does not work. In fact I begin to question whether this custom user and group will work at all.
For instant, instead of above codes. This time around I did XML configuration as in mondhs solution. And make sure that piece of XML beans configuration is read by spring.
Then I make sure this piece of code from this activiti-spring-boot repo is executed
@Bean
InitializingBean usersAndGroupsInitializer(
final IdentityService identityService) {
final Logger log = LoggerFactory.getLogger(this.getClass());
return new InitializingBean() {
public void afterPropertiesSet() throws Exception {
Group group = identityService.newGroup("user");
group.setName("users");
group.setType("security-role");
identityService.saveGroup(group);
User admin = identityService.newUser("rootadmin");
admin.setPassword("admin");
identityService.saveUser(admin);
}
};
}
My finding is that IdentityService still use the act_id_user and act_id_group table. Instead of my custom table. Concluding that Identity Service is still not using my customized user and group factory/manager.
Does this means problem with my code or the engine will not use my custom user and group table and I have to manually do stuff like creating group whenever the engine read diagram with group set?
With that said, I still did not see group created in act_id_group or my own custom table when diagram is read by the engine. So I am still thinking that I have not done this right. But kinda hard to not do it right when it is just XML configuration that I am sure is being read and configured by spring.
from spring-boot-with-activiti-example.
use your above code, i also can't not use custom GroupManager & UserManager, can you please give a doucument for it.
from spring-boot-with-activiti-example.
i used version 5.17
from spring-boot-with-activiti-example.
my code is below:
@component(value="myGroupManagerFactory")
public class ActivitiGroupManagerFactory implements SessionFactory {
@Autowired
private TGroupRepository groupDao;
@Override
public Class<?> getSessionType() {
return GroupIdentityManager.class;
}
@Override
public Session openSession() {
return new ActivitiGroupManager(groupDao);
}
}
@component(value = "myUserManagerFactory")
public class ActivitiUserManagerFactory implements SessionFactory {
@Autowired
private TUserRepository userDao;
@Override
public Class<?> getSessionType() {
return UserIdentityManager.class;
}
@Override
public Session openSession() {
return new ActivitiUserManager(userDao);
}
}
@configuration
public class ActivitiConfiguration {
@resource(name = "myGroupManagerFactory")
private SessionFactory groupManagerFactory;
@Resource(name = "myUserManagerFactory")
private SessionFactory userManagerFactory;
@Bean
Object getProcessEngineConfigurationConfigurer(SpringProcessEngineConfiguration pec) {
new ProcessEngineConfigurationConfigurerImpl().configure(pec);
return null;
}
class ProcessEngineConfigurationConfigurerImpl implements ProcessEngineConfigurationConfigurer {
public void configure(SpringProcessEngineConfiguration pec) {
SessionFactory[] factories = new SessionFactory[] { groupManagerFactory, userManagerFactory };
pec.setCustomSessionFactories(Arrays.asList(factories));
// Map<Class<?>, SessionFactory> sessionFactories = new
// HashMap<Class<?>, SessionFactory>();
//
// sessionFactories.put(ActivitiUserManagerFactory.class,
// userManagerFactory);
// sessionFactories.put(ActivitiGroupManagerFactory.class,
// groupManagerFactory);
//
// pec.setSessionFactories(sessionFactories);
}
}
}
from spring-boot-with-activiti-example.
finally, replace these code will be ok.
class ProcessEngineConfigurationConfigurerImpl implements ProcessEngineConfigurationConfigurer {
public void configure(SpringProcessEngineConfiguration pec) {
// SessionFactory[] factories = new SessionFactory[] { groupManagerFactory, userManagerFactory };
// pec.setCustomSessionFactories(Arrays.asList(factories));
Map<Class<?>, SessionFactory> sessionFactories = pec.getSessionFactories();
sessionFactories.put(userManagerFactory.getSessionType(), userManagerFactory);
sessionFactories.put(groupManagerFactory.getSessionType(), groupManagerFactory);
pec.setSessionFactories(sessionFactories);
}
}
from spring-boot-with-activiti-example.
@sendreams I follow your step,it does't work, can you put your whole code.
Best Wishes!
from spring-boot-with-activiti-example.
Thank you very much!
from spring-boot-with-activiti-example.
Hello @jbarrez,
Could you please check this related question Configure Activiti to reuse the existing user/group data in Spring Boot
Thank you.
from spring-boot-with-activiti-example.
Related Issues (7)
- tenantId in the auto deployment ? HOT 1
- how to config email in application.properties HOT 1
- Unable to Start Spring Application due to Error creating bean with name 'requestMappingHandlerMapping'
- spring boot doesn't start because of Lifecycle exception HOT 4
- spring boot starter parent HOT 1
- Unable to import BPMN xml file on activiti.alfresco.com
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot-with-activiti-example.