I have created a POC with Spring Boot and JPA using spring-boot-starter-data-jpa and my solution works pretty well. My issue arises when i try to add the same solution to an old project which uses Spring 4 and hibernate JPA 2.1 version. When I deployed my war in weblogic, the first error i got was could not autowire the repository so i added the the @EnableJpaRepositories
. I even tried to add spring.datasource.jndi-name=EXAMPLE_Data_Source
where EXAMPLE_Data_Source
is my weblogic datasource but no luck.
The application class:
@Configuration
@EnableWs
@ComponentScan("com.example.package")
@EnableJpaRepositories(basePackages = {"com.example.repository","com.example.entity"})
public class AppConfig extends WsConfigurerAdapter { //WsConfigurerAdapter is spring-ws-core 2.2.0 Release
@Autowire
MyRepository repository;
The Repository class:
public interface MyRepository extends JpaRepository<EntityClass, EntityPKey> {
@Query("select c from EntityClass c where ID = :param1 and TYPE = :param2 and :param3 between FROM_DATE and TO_DATE ")
EntityClass entityClass(@Param("param1") int param1, @Param("param2")
char param2, @Param("param3") Date param3);
}
Now i get the get the error below:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined" weblogic.application.ModuleException:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
Truncated. see log file for complete stacktrace
I have to get it working on the old spring project which is deployed in weblogic.
Questions 1: Will this way of solving my issue work for the Spring framework or only with Springboot?
Question 2: What configurations I am missing?
Question 3: Please point me to a working example. I am struggling to make this work.
Spring webmvc and spring-tx is version 4.0.6
Please be a bit more detailed in your explanation. I am still very junior.
Thanks in advance.