I have a wird problem with Spring. I'm working on a small mvc application and after some work I'm faceing such a problem:
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userServiceImpl' for bean class [com.(...).servlet3.UserServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.(...).service.UserServiceImpl]
This exception looks like sefl-explain but there is one thing wird: I do not have such class as [com.(...).servlet3.UserServiceImpl]. I used to have, but moved to another package. My structure looks like this:
Does anyone has faced such a problem?
You have to check get and set method in bean for path bean definition or path name seems duplicate.
Related
I am upgrading my existing axon-core : 3.3.6 to 4.0.4 and facing the issue while building the application how may I resolve it?
Here is the exception:
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'commandGateway' defined in class path
resource
[org/axonframework/springboot/autoconfig/AxonAutoConfiguration.class]:
Unsatisfied dependency expressed through method 'commandGateway'
parameter 0; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type 'org.axonframework.commandhandling.CommandBus'
available: more than one 'primary' bean found among candidates:
[commandBus, distributedCommandBus]
The shared exception mentions:
more than one 'primary' bean found among candidates: [commandBus,
distributedCommandBus]
This probably means that you have your CommandBus bean annotated with #Primary. If so, you can remove that annotation, as the DistributedCommandBus instance is the one that should act as primary only.
If this is not the case, you can resolve the issue by explicitly configuring a CommandGateway. That way, you override Axon's auto configuration, which apparently has difficulties resolving "the" Command Bus to use. The class you'd be looking to construct is the DefaultCommandGateway, which takes a reference to the CommandBus to which it acts as a gateway. You will probably want to inject the DistributedCommandBus.
As a last remark, Axon has already progressed to version 4.5. A lot of improvements have been made along the way that may be worthwhile. It is also nu unlikely that some of the auto configuration issues you're bumping into have been addressed in some intermediate version.
For Springboot application using optaplanner-spring-boot-starter, the cloudbalancing problem solution works fine with one planning solution and solverManager similar to
https://github.com/DuncanDoyle/optaplanner-sbs-cloud-balancing/tree/master/optaplanner-sbs , but when multiple planning solutions are defined and called using a solverManager it throws an error
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'solverFactory' defined in class path
resource
[org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]:
Unsatisfied dependency expressed through method 'solverFactory'
parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'solverConfig' defined in class path resource
[org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.optaplanner.core.config.solver.SolverConfig]: Factory
method 'solverConfig' threw exception; nested exception is
java.lang.IllegalStateException: Multiple classes ([class
com.test.model.PRCaseAssignment, class
com.test.model.CaseAssignment]) found with a
#PlanningSolution annotation.
How can we define multiple #PlanningSolution classes and call using the solverManager, are there any kind of Qualifiers which needs to be annotated? Any help is appreciated. Thanks.
May I ask what is the use case for having multiple solution classes?
The optaplanner-spring-boot-starter supports only a single solver configuration and thus only a single solution class. So does the SolverManager API: you can submit multiple planning problems to the SolverManager, but they have to be of the same type (solution class) and share the same solver configuration. To submit a planning problem of a different type, you have to create a new instance of the SolverManager. See the documentation on how to create an instance of the SolverManager manually.
Im trying to follow the guide for Hybris123 version 19.05, but when creating new services I get a problem where the spring framework does not recognize my service.
I tried to change the neme of the variable but honestly Im not sure what to do.
The errorIm getting is "org.springframework.beans.FatalBeanException: Context hybris Global Context Factory couldn't be created correctly due to, Error creating bean with name 'applicationEventMulticaster': Unsatisfied dependency expressed through method 'setAllDecorators' parameter 0; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [concerttours.service.impl.DefaultBandService] for bean with name 'defaultBandService' defined in class path resource [concerttours-spring.xml]; nested exception is java.lang.ClassNotFoundException"
The code Im using in spring is:
<alias name = "defaultBandService" alias = "DefaultBandService"/>
<bean id = "defaultBandService" class = "concerttours.service.impl.DefaultBandService" >
<property name = "bandDAO" ref = "bandDAO" />
</bean>
And when I use the IDE for looking a file with the name DefaultBandService it recognizethe service that Im trying to use but the spring framework does not. In the service tried to use a spring Tag like component but it didnt work.
I expect spring to recgonize the bean and let me run the hybris server
Use your IDE to look for the class(i.e DefaultBandService).
Check the package of the class(most probably the first line of the file).
Make sure that the package is specified correctly in your spring xml File.
Make sure that the class is in the same extension as the Spring file. If it is not, then a dependency needs to be added in extensioninfo.xml.
Run "ant clean all" and start the Server again.
I'm working on an update version of grail-oauth-plugin that support last spring-oauth
My plugin version works good and I have implemented a workin oauth2 server.
But now I want to add a custom-grant defined like this
def doWithSpring = {
myTokenGranter(MyTokenGranter)
xmlns oauth:"http://www.springframework.org/schema/security/oauth2"
oauth.'authorization-server'( /* ... many definitions here ... */){
/* ... many definitions here ... */
oauth.'custom-grant'('token-granter-ref': "myTokenGranter")
}
}
But I get an exception telling me:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myTokenGranter'
But the bean myTokenGranter is defined as you can see. And If I remove the custom-grant definition the project starts and I can access the myTokenGranter bean.
Looking to a fullstack trace I see that the exception occur in the spring oatuh2 server bean definition parse AuthorizationServerBeanDefinitionParser.java in the line where it try to find my bean
parserContext.getRegistry().getBeanDefinition(customGranterRef);
where customGranterRef = "myTokenGranter"
so I suspect there is a bug in Spring Ouath or in Grails BeanBuilder that does not let my "myTokenGranter" to be visible in the server parser. Or making some error in grails bean definition DSL.
Thank you for your interest.
Debugging the app more deeply I have found that the problem probably is in how grails BeanBuilder work in translating namespaced spring DSL.
If I debug the point where my bean is checked (in AuthorizationServerBeanDefinitionParser.java)
at row
parserContext.getRegistry().getBeanDefinition(customGranterRef);
if I check che result of
parserContext.getRegistry().getBeanDefinitionNames()
it show me only this beans
[org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.annotation.internalPersistenceAnnotationProcessor
org.springframework.aop.config.internalAutoProxyCreator
org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0
org.springframework.transaction.interceptor.TransactionInterceptor#0
org.springframework.transaction.config.internalTransactionAdvisor
oauth2TokenGranter
oauth2AuthorizationCodeServices
oauth2AuthorizationRequestManager]
And not all other decleared beans...
The problem exist even if I move the ouath server declaration inside resources.xml, keeping my custom token granter bean declaration inside resources.groovy.
But the problem solves if I move the custom token bean declaration inside resources.xml.
I don't really know how the BeanBuilder DSL works, but it seems like the problem is there if there is a problem (your example works just fine in XML). Can you do it in two steps, so the bean definition for myTokenGranter is definitely available when the OAuth2 namepsace is handled?
Solved hacking Spring Security Oauth
see this commit
I am using another application's service,since everything is already made and done.
My application is to use the interface class inside the application jar.
but something seem to be wrong when this code is called.
BeanFactory factory = new ClassPathXmlApplicationContext( "/Context-Controller.xml");
even if my Context-Controller.xml has this code
<context:component-scan base-package="com.package" />
My error.
Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No unique bean of type
[com.package.ServiceIamUsing] is
defined: Unsatisfied dependency of
type [interface
com.package.ServiceIamUsing]: expected
at least 1 matching bean
this is how i autowired it on my applciation.
public class MyAppDao implements IMyAppDao {
#Autowired
#Qualifier("serviceIamUsing")
private ServiceIamUsing serviceIamUsing;
//More codes here
}
jay, try the following:
- eliminate the forward-slash "/"
- in your application context xml file, try to import the application context from your external jar file if it has any --> import resource="classpath*:/META-INF/spring/*.xml"
let me know if it does/doesn't work.
Is there, in fact, an instance of ServiceIamUsing in the jar that is also Spring-annotated (#Component, #Service, etc.)? It's possible this is the case, but I'd like to clarify.
If not, does the jar expose a Spring context file you can import, thus adding the additional beans to your context for autowiring?