I am using two Spring Entity manager, Arrango and JPA for my application.
#EnableSwagger2
#ComponentScan(basePackages = "com.xyz.abc")
#EnableArangoRepositories(basePackages = {"com.xyz.abc"})
#EnableJpaRepositories(basePackages = {"com.xyz.abc"})
#EntityScan(basePackages = "com.xyz.abc")
#SpringBootApplication
#EnableEurekaClient
#EnableDiscoveryClient
#EnableProcessApplication
As can be seen, I am Enabling repository access. Now when I run my application, I get the following error.
The bean 'XYZRepository', defined in com.xyz.abc.core.data.repository.XYZRepository defined in #EnableJpaRepositories declared on MYControllerAPP, could not be registered. A bean with that name has already been defined in com.xyz.abc.core.data.repository.XYZRepository defined in #EnableArangoRepositories declared on MyControllerAPP and overriding is disabled.
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
When I add overriding bean definition to my application.yml file.
The error changes to:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'qualityService': Unsatisfied dependency expressed through field 'master'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'masterDataRepository' defined in com.xyz.abc.core.data.repository.MasterDataRepository defined in #EnableJpaRepositories declared on QualityControllerApp: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.xyz.abc.core.data.model.MasterData
this is my MasterDataRepository Interface:
interface MasterDataRepository extends ArangoRepository<MasterData, String>
{
//Hibernate
}
I think the base problem with:
#EnableArangoRepositories(basePackages = {"com.xyz.abc"})
#EnableJpaRepositories(basePackages = {"com.xyz.abc"})
You should to set different packages to different repository providers. You won't be able to use one Entity class with different repositories. Try to separate ArangoRepository entities and JpaRepository entities.
Related
Tried to create two separate ElasticsearchRestTemplate using qualifier bean and gave different elasticsearchTemplateRef to ElasticsearchRepository , but its not working.
Getting error:
The bean 'elasticsearchTemplate', defined in class path resource [com/paytm/digital/search/ingestion/elastic/ElasticConfigK8.class], could not be registered. A bean with that name has already been defined in class path resource [com/paytm/digital/search/ingestion/elastic/ElasticConfig.class] and overriding is disabled.\n\nAction:\n\nConsider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-
Cannot register bean definition
I have a spring boot application, say A, which has a bean defined in xml:
<bean class="com.learning.MyBean" name="myBean">
<property name="maxAngle" value="360" ></property>
</bean>
Bean is:
public class MyBean {
#Value("${maxAngle}")
public void setMaxAngle(double maxAngle) {
....
}
}
When I run A independently, all is fine. But when I include it as dependency in another spring boot application, then I get error related to injection of maxAngle:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBean': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'maxAngle' in value "${maxAngle}"
What can be the issue here?
#Value annotation is used to bind properties defined in application.properties or application.yaml.
Try adding maxAngle=360 to application.properties or application.yaml and remove it from bean XML defination
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 large Spring Project, whose beans are mostly created via the #Component annotation on classes. I'm slowly tring to move the bean definition to the spring.xml config file.
I however, get a the following error whenever I try to autowire a bean created in the xml config file into a bean created via the #Component annotation.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ComponentBean' defined in class path resource [spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'xmlBean' of bean class [myproject.XmlBean]: Bean property 'xmlBean' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
In my spring.xml:
<bean id="xmlBean" class="myproject.XmlBean" />
Trying to autowire beans into #Component beans as follows does not work:
#Component
class ComponentBean {
#Autowired
private XmlBean xmlBean;
// Bean setters and getters
}
Is there a way by which I could marsh up the two, as I slowly port my bean definitions to the spring.xml config file.
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")