The bean 'methodSecurityInterceptor', defined in class path resource [org/activiti/spring/boot/MethodSecurityConfig.class], could not be registered - spring

***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'methodSecurityInterceptor', defined in class path resource [org/activiti/spring/boot/MethodSecurityConfig.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
I use the SpringBoot 2.2.12 and SpringSecurity 5.2.8 and activiti 7.1.0.M4 then get the error.
I think it may coursed by activiti conflict with SpringSecurity.

I think. If there is a conflict between the two framework bean naming definitions.You can try to customize one of them

Related

springboot app looking for GenericResponseService bean

I am new to springboot.
Doing a migration of my service (kotlin)following a guide written at work.
Got this weird exception and cannot find any documentation.
Parameter 3 of method multipleOpenApiResource in org.springdoc.webflux.core.MultipleOpenApiSupportConfiguration required a bean of type 'org.springdoc.core.GenericResponseService' that could not be found.
Action:
Consider defining a bean of type 'org.springdoc.core.GenericResponseService' in your configuration.
Should I define this bean at my #Configuration?
Is this a symptom of dependency missing or bad dependency wiring?
One of my beans was called ResponseBuilder and it conflicted with spring boot.
Sorry for the trouble

Spring Integration causes multiple beans error

I'm using Spring Boot and trying use Spring integration (because I want to use its SFTP client). But I got the following error:
Description:
Parameter 0 of constructor in com.example.demo.service.ServiceOne required a single bean, but 2 were found:
- applicationTaskExecutor: defined by method 'applicationTaskExecutor' in class path resource [org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.class]
- taskScheduler: defined in null
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the bean that should be consumed
I'm sure that the error happens after adding dependencies for spring-integration. I've tried to use #Qualifier("applicationTaskExecutor") and creating a bean with #Primary annotation but still unable to run the application. How to fix it?
As error stated there are two TaskExecutor beans in the application context.
One is auto-configured by the TaskExecutionAutoConfiguration and another by Spring Integration for its pollers features which is essentially a TaskScheduler.
What the error description suggest is to use a #Qualifier("applicationTaskExecutor") on the ServiceOne 's Parameter 0 of constructor. You don't need to have #Primary bean because the story is about beans created outside of your code.

The bean 'methodSecurityInterceptor', defined in class path resource and overriding bean is disabled

I am using spring boot 2.1.6.RELEASE and using some third party framework to perform security specific activities. This third party library using spring security 4.2.3.RELEASE.
When I ran the application, I got below error.
The bean 'methodSecurityInterceptor', defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/thirdparty/configSecurityConfig.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
I know, I can solve the problem by setting below configuration.
spring:
main:
allow-bean-definition-overriding: true
But is there any way to specify my application to use the spring security (4.2.3.RELEASE) of third party library not from spring boot 2.1.6.RELEASE.

Errors while running tests

I am trying to run my tests using mvn clean install, but these errors stop the process. I tried debugging using JUNIT but nothing shown on the console.
these are the logs :
com.datamint.service.impl.EmailServiceImplDevTest:Error creating bean with name'entityManagerFactory'defined in class path resource
[orm.xml]:BeanPostProcessor before instantiation of bean failed;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'org.springframework.security.methodSecurityMetadataSourceAdvisor':Cannot resolve reference to bean'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0'while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0':Cannot create inner bean'(inner bean)'of type[org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource]while setting constructor argument with key[0];nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'(inner bean)':Cannot create inner bean'(inner bean)'of type[org.springframework.security.access.expression.method.ExpressionBasedAnnotationAttributeFactory]while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'(inner bean)':Cannot resolve reference to bean'expressionHandler'while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'expressionHandler'defined in class path resource
[spring-security.xml]:Cannot resolve reference to bean'permissionEvaluator'while setting bean property'permissionEvaluator';nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'permissionEvaluator'defined in class path resource
[spring-security.xml]:Cannot resolve reference to bean'aclService'while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'aclService'defined in class path resource
[spring-security.xml]:Cannot resolve reference to bean'lookupStrategy'while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'lookupStrategy'defined in class path resource
[spring-security.xml]:Cannot resolve reference to bean'aclCache'while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'aclCache'defined in class path resource
[spring-security.xml]:Cannot create inner bean'org.springframework.cache.ehcache.EhCacheFactoryBean#a512c9c'of type[org.springframework.cache.ehcache.EhCacheFactoryBean]while setting constructor argument;nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'org.springframework.cache.ehcache.EhCacheFactoryBean#a512c9c'defined in class path resource
[spring-security.xml]:Cannot create inner bean'org.springframework.cache.ehcache.EhCacheManagerFactoryBean#68394e81'of type[org.springframework.cache.ehcache.EhCacheManagerFactoryBean]while setting bean property'cacheManager';nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name'org.springframework.cache.ehcache.EhCacheManagerFactoryBean#68394e81'defined in class path resource
[spring -security.xml]:Invocation of init method failed;nested exception is net.sf.ehcache.CacheException:Another unnamed CacheManager already exists in the same VM.Please provide unique names for each CacheManager in the config or do one of following:
What can be the problem? thanks
The cause of the problem is that with the default settings, you cannot have multiple processes sharing the same EhCache. Taken from here
CacheManager supports two creation modes: singleton and instance.
Versions of Ehcache before version 2.5 allowed any number of
CacheManagers with the same name (same configuration resource) to
exist in a JVM. Therefore, each time new CacheManager(...) was called,
a new CacheManager was created without regard to existing
CacheManagers. Calling CacheManager.create(...) returned the existing
singleton CacheManager with the configured name (if it existed) or
created the singleton based on the passed-in configuration.
Ehcache 2.5 and higher does not allow multiple CacheManagers with the
same name to exist in the same JVM. CacheManager() constructors
creating non-Singleton CacheManagers can violate this rule, causing a
NullPointerException. If your code may create multiple CacheManagers
of the same name in the same JVM, avoid this error by using the static
CacheManager.create() methods, which always return the named (or
default unnamed) CacheManager if it already exists in that JVM. If the
named (or default unnamed) CacheManager does not exist, the
CacheManager.create() methods create it.
One solution that will fix your problem (but will slow down the execution of the tests), is to add #DirtiesContext to each of your tests that loads the Spring configuration. That will force Spring to recreate all the beans upon running each test class and you'll be able to sidestep the problem.
A solution I prefer in these cases is to run the tests (that don't test caching) using a different profile, where caching is not configured. That way you don't need #DirtiesContext and therefore the execution time of the tests if much better

conflicts with existing, non-compatible bean definition of same name and class after proguard obfuscation

after Proguard obfuscation i get the following error :
Unexpected exception parsing XML document from ServletContext resource
[/WEB-INF/applicationContext.xml]; nested exception is
java.lang.IllegalStateException: Annotation-specified bean name 'a'
for bean class [com.company.project.b.a.a.a] conflicts with existing,
non-compatible bean definition of same name and class
[com.company.project.a.a]
i'm using annotation based spring configuration , how can i avoid having two classes with the same name using Proguard because Spring doesn't allow two beans to have the same name.
I'm not sure if this is what you want, but you can specify bean name in #Component (and stereotypes #Repository, #Service and #Controller) value:
#Component("myBeanName")
public class MyBean {
}
I had the same problem and nothing else was helping out. Sometimes the problem occurs if you have moved your classes around and it refers to old classes, even if they don't exist.
In this case, just do this :
mvn eclipse:clean
mvn eclipse:eclipse
This worked well for me.
Another cause; you may have different versions of Spring in your classpath, for example, spring 2.x with spring 3.x. In such condition, beans seem to be loaded twice. If you use maven, check if a module does not import an old version of Spring (mvn dependency:tree) and remove it by excluding the involved spring artifact (exclusions).

Resources