I use spring-boot-starter-data-jpa for get data from mysql.
When my project structure is (Project.java file is in application package) everything works well, but when I put Project.java entity file to entities package I got bellow exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controller': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.gehive.microservice.data.repositories.ProjectRepository com.gehive.microservice.application.Controller.repo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class com.gehive.microservice.data.entities.Project
work without exceptions:
if structure like this I got exception:
The default #ComponntScan for Spring boot(the one that #SpringBootApplication inherits) scans the current package and all it's sub packages.
In the first case Project.java is in the same package as Application.java, so it's ok.
To make Project work from another package change the name to com.gehive.microservice.application.entities or whatever sub-package of the one with the main class.
Usually I keep the bootstraping class and all the configuration classes in package named <com|org|etc>.<myCompany>.<myProject> and then create the other packages as sub packages of this one.
Spring Data JPA has some other conditions related to the packages. Take a look at the Docs
Related
The project current runs fine via IntelliJ. Its built with Java 11, spring-boot 2.4.3, and gradle 6.8.3
The error as I read it states that it cannot find a 'RestDriver'( which is annotated as #RestController) nor the interface 'DriverService' which has no annotations on it. That class uses a a class annotated with #Service 'DriverServiceImp'.
Its as if I will have to state in main where these classes are because it cannot find them.
2021-10-21 12:04:45 [main] ERROR o.s.boot.SpringApplication at 856 - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'restDriver':
Unsatisfied dependency expressed through field 'driverService';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'DriverService': Lookup method resolution failed;
nested exception is java.lang.IllegalStateException:
Failed to introspect Class [com.xxx.wfmDriverservice.service.DriverServiceImp] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#5c7fa833]
I need to migrate project from Java 7 to Java 8 and deploy it on WAS 9 (before this migration application was running on Java 7 and WAS 8.5)
So, I upgraded Java to version 8 and add some necessary dependencies in pom.xml but I get stuck with this errors in log file and actually don't know what should I do to resolve it. Am I missing some dependency? Should I exclude some jar files?
Also, for this project class loader was configured to parent last in Websphere.
Caused by: java.lang.LinkageError: loading constraint violation when
resolving method
"javax/xml/bind/Unmarshaller.unmarshal(Ljavax/xml/stream/XMLStreamReader;Ljava/lang/Class;)Ljavax/xml/bind/JAXBElement;"
: loader "com/ibm/ws/classloader/CompoundClassLoader#ebfd011c" of
class "org/apache/cxf/configuration/spring/JAXBBeanFactory" and loader
"com/ibm/oti/vm/BootstrapClassLoader#38c22f6e" of class
"javax/xml/bind/Unmarshaller" have different types for the method
signature at
org.apache.cxf.configuration.spring.JAXBBeanFactory.createJAXBBean(JAXBBeanFactory.java:51)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name AuthenticationServicePort.jms-conduit':
Cannot create inner bean '(inner bean)' of type
[org.apache.cxf.configuration.spring.JAXBBeanFactory] while setting
bean property 'clientConfig'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)': Instantiation of bean failed;
nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public static java.lang.Object
org.apache.cxf.configuration.spring.JAXBBeanFactory.createJAXBBean(javax.xml.bind.JAXBContext,java.lang.String,java.lang.Class)]
threw exception; nested exception is java.lang.LinkageError: loading
constraint violation when resolving method
"javax/xml/bind/Unmarshaller.unmarshal(Ljavax/xml/stream/XMLStreamReader;Ljava/lang/Class;)Ljavax/xml/bind/JAXBElement;"
: loader "com/ibm/ws/classloader/CompoundClassLoader#ebfd011c" of
class "org/apache/cxf/configuration/spring/JAXBBeanFactory" and loader
"com/ibm/oti/vm/BootstrapClassLoader#38c22f6e" of class
"javax/xml/bind/Unmarshaller" have different types for the method
signature
Does anybody knows what should I do? Or what I am doing wrong?
Many thanks in advance
OK, I figured it out
Here is what I did:
Upgrade jaxb-api dependency to version 2.2
Upgrade jaxb-impl dependency to version 2.1.9
Add cxf-rt-transports-http dependency (version 2.7.11)
Remove all JAXB jar files and STAX jar files from lib folder in exported war, but I left only stax2-api-3.1.4.jar inside it
The error is actually a Conflicting persistence unit, which is something defined in a component, which is a parent for my project. My spring context is taking that conflicting unit from both the target/classes folder of the component and the jar stored in the local maven repository as well. Why is this happening? This is the error trace:
Error creating bean with name 'persistenceUnitManager' defined in class
path resource [spring-config/framework-persistence-context.xml]: Invocation
of init method failed; nested exception is java.lang.IllegalStateException:
Conflicting persistence unit definitions for name 'persistence-framework':
file:/D:/fw/projects/springproj-core-project/springproj-core-framework/target/classes,
file:/C:/Users/prateek.chachra/.m2/repository/com/springproj/
springproj-core-framework/1.4.M1/springproj-core-framework-1.4.M1.jar
EDIT: Before reading the question: deleting the folder in wildfly deployment "solved" the issue. But I didn't put back my code for the other DB. Is the way I did it was right?
I was working this morning, everything was going fine.
I added a dependency which is the core of another maven project and the goal was to use that project to add data in the database of that project, not the one of my current project.
So I tried a lot of stuff, but at the end it was working. And then, I left to go eat.
The server is host on my computer, so localhost and I left it like that for about an hour.
Here's what I did:
Create new hibernate.cfg.xml in src/main/resources with properties.
So I had 2 hibernate.cfg.xml in my project. The original one in src/main/resources/my/hibernate/package/ and the new one in the default package.
In my code ->
Configuration cfg = new Configuration();
cfg.configure();
Note that before doing only that, I was setting the properties programmatically and it was working fine.
I thought it was taking the one in default package. That was working earlier.
So I came back, try to run the application and get this exception:
Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
I haven't touch a thing... so I removed all my work (the new hibernate.cfg.xml too), restarted the server, even the computer.
I read about the exception, it says that maybe I have two dom4j, or that I need to put <scope>provided</scope> to some dependencies.
I added the scope everywhere, removed the dependency of the other project, but it won't help.
I have these logs in my wildfly server.log
WFLYCTL0186: Services which failed to start:
service jboss.undertow.deployment.default-server.default-host./PROJECT_NAME:
org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./PROJECT_NAME:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'firstControllerInMyDispatcher':
Unsatisfied dependency expressed through field 'DAO_name':
Error creating bean with name 'DAO_name' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]:
Cannot resolve reference to bean 'mySessionFactory' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]:
Invocation of init method failed;
nested exception is org.hibernate.InvalidMappingException:
Unable to read XML;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'DAO_name' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]:
Cannot resolve reference to bean 'mySessionFactory' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]:
Invocation of init method failed;
nested exception is org.hibernate.InvalidMappingException:
Unable to read XML
The dom4j exception only shows in the Netbeans console log and it's after all those same lines:
"{\"WFLYCTL0080: Failed services\" => {\"[previous exceptions lines]
Caused by:
org.dom4j.DocumentException:
org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception:
org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory\"}}"
I'm clueless, can anyone help with this? Thanks.
I ran into a problem trying to use Spring-roo in STS ide.
I created a project and added EclipseLink ORM, and that is about it.
In persistence.xml i added all the details for the database connectivity.
When I tried to run the spring project, it failed to show the default jspx page i was expecting.
Here is the error:
2012-07-02 10:45:39,411 [pool-2-thread-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [/home/ubuntu/springsource/vfabric-tc-server-developer-2.7.0.RELEASE/spring-insight-instance/wtpwebapps/SpringRooStats/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/home/ubuntu/springsource/vfabric-tc-server-developer-2.7.0.RELEASE/spring-insight-instance/wtpwebapps/SpringRooStats/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.reflect.UndeclaredThrowableException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
It is complaining it seems that it needs to create an entity manager, but I think that
it should not since it should run a project that does not connect to a database and just run a simple jspx page.
Does one need to go thru the whole thing with entities just to run a simple project.
Hope someone can help.
Your applicationcontext.xml has a transactionManager defined. This needs a entity manager. Your would need to remove the transaction manager or add the entity manager.
I'm also not sure why you added the ORM framework if your not going to use it.