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.
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.
I'm working on One Hippo CMS, when I run the Tomcat server I'm getting this error
5.02.2019 18:23:45 ERROR main [DefaultHstSiteConfigurer.initializeComponentManager:264] HstSiteConfigurer: ComponentManager initialization failed.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.hippoecm.hst.content.beans.manager.ObjectConverter' defined in class path resource [org/hippoecm/hst/site/container/SpringComponentManager-content-beans.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Annotated class 'org.example.myproject.beans.Urldemo' for primarytype 'myproject:urldemo' is a duplicate of already registered class 'org.example.myproject.beans.Simple'. You might have configured a bean that does not have a annotation for the jcrType and inherits the jcrType from the bean it extends, resulting in 2 beans with the same jcrType. Correct your beans.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) ~[spring-beans-5.1.1.RELEASE.jar:5.1.1.RELEASE]
Check the annotations on:
org.example.myproject.beans.Urldemo
org.example.myproject.beans.Simple
They should each have an annotation similar to:
#Node(jcrType = "project:doctype")
Each needs a unique jcrType value.
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.
I'm trying to set up a running service which uses Elasticsearch with Shield. However when I try to start the service I get the following error:
org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private java.util.List com.company.AppConfig.identConfigs;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'demoident' defined in URL [file:C:/path/to/config/foo.xml]:
Cannot resolve reference to bean 'bar_client' while setting bean property 'searchClients'
with key [TypedStringValue: value [default], target type [null]];
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'bar_client' defined in URL
[file:C:/path/to/config/foo.xml]: Bean instantiation via constructor failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.company.ElasticSearchClient]:
Constructor threw exception; nested exception is
org.elasticsearch.common.inject.CreationException: Guice creation errors:
1) A binding to org.elasticsearch.shield.transport.filter.IPFilter was already configured
at _unknown_. at _unknown_
2) A binding to org.elasticsearch.shield.transport.ClientTransportFilter was already configured
at _unknown_. at _unknown_
3) A binding to org.elasticsearch.shield.ssl.ClientSSLService was already configured
at _unknown_. at _unknown_
4) A binding to org.elasticsearch.shield.ssl.ServerSSLService was already configured
at _unknown_. at _unknown_
4 errors
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
(Sorry for the ugly formatting of stacktrace, feel free to edit for readability)
If I remove the Maven dependency for Elasticsearch Shield then the service starts as expected, without stacktraces, but obviously won't be able to execute any queries because of the exclusion of Shield.
Any help or input at all would be very appreciated.
Edit: I realized that the error is thrown by the Java client, not Elastic itself.
We have a sample app that showcases some things we are doing client side. It pulls in a few internal libraries to get everything functional. It dummies in some hard-coded data so it doesn't have to be concerned with any kind of persistence mechanism.
In some of these libraries that are pulled in, there are spring data jpa repositories. Something like this:
public interface MyLibraryEntityRepository extends JpaRepository<MyLibraryEntity, Long>
{
//...
}
When the server starts up, I get an error like this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myLibraryEntityRepository': Cannot create inner bean '(inner bean)#788f64f1' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#788f64f1': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
It can't find the entityManager, but I don't want to have to use an entityManager. So, in an attempt to override the myLibraryEntityRepository bean, I added the following to my Java config:
#Bean
public MyLibraryEntityRepository getMyLibraryEntityRepository()
{
return myDummyImpl();
}
However, this results in the same error.
Is there any way I can override the bean definition for the spring data jpa repository so that I can use my own dummy implementation and not have to configure an entityManager in my app?
You can use #Bean(name="dummyBean") and the in the #Autowired use the annotation #Qualifier("dummyBean")