Failed to read bean names "entityMangerFactory" from applicationContext in Springboot

28 Views Asked by At

I am migrating a spring application to springboot and getting following error. Its complaining about bean not available from applicationcontext but the file is loaded successfully. Description:

Field appRepository in com.td.api.roleent.resources.ApplicationsResource required a bean named 
'entityManagerFactory' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

09:19:30,541 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 143) MSC000001: 
Failed to start service jboss.deployment.unit."com.td.api.roleent-1.1.15.war".undertow- 
deployment: org.jboss.msc.service.StartException in service 
jboss.deployment.unit."com.td.api.roleent-1.1.15.war".undertow-deployment: 
java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'applicationsResource': Unsatisfied dependency expressed through 
field 'appRepository'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'applicationRepository' defined in 
com.td.api.roleent.db.entity.repositories.ApplicationRepository defined in 
@EnableJpaRepositories declared on RoleApiMain: Cannot create inner bean '(inner 
bean)#290994fc' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting 
bean property 'entityManager'; nested exception is o o 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner 
bean)#290994fc': Cannot resolve reference to bean 'entityManagerFactory' while setting 
constructor argument; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 
'entityManagerFactory' available

Main class(if I remove EnableJPARepository the entitymnagarefactory is gone but still it couldn't find the Apprepository bean:

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@ComponentScan(basePackages = { "com.td.api.roleent"})
@EntityScan(basePackages = { "com.td.api.roleent"})
@EnableJpaRepositories(basePackages = { "com.td.api.roleent"})
public class RoleApiMain extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(RoleApiMain.class);
    }

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(RoleApiMain.class);
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebAppConfig.class);
        app.addListeners(new ApplicationPidFileWriter("./shutdown.pid"));
        app.run(args);
    }
}

ApplicationResource class:

public class ApplicationsResource {

    // Initialization of the logger.
    static final Logger LOGGER = LoggerFactory
            .getLogger(ApplicationsResource.class);

    private final String OAUTH_TOKEN_CREATION_FAILED = "Err1751";

    private String anyExternalizedProperty;

    @Autowired
    ApplicationRepository appRepository;

    @Autowired
    UserPermissionService userPermissionService;

    @Autowired
    ApplicationHierarchyService appHierarchyService;

    @Autowired
    HierachyMappingService hierarchyService;
}

ApplicationRepository class:

@Repository
@Component
public interface ApplicationRepository extends PagingAndSortingRepository<ApplicationEntity, Serializable>{
    
    
    ApplicationEntity findByAppId(String appId);
}

ApplicationContext:

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
    <constructor-arg index="0" ref="hikariConfig"/>
</bean>

  
<tx:annotation-driven/>

<bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
    <property name="packagesToScan" value="com.td.api.roleent.db.entity, com.td.coreapi.common.jwksdk.db.entity"/>
    <property name="jpaProperties">
        <props>
            <prop key="jboss.as.jpa.managed">false</prop>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.ejb.naming_strategy">${hibernate.ejb.naming_strategy}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.default_schema">${hibernate.default_schema}</prop>
        </props>
    </property>
</bean>

Thanks in advance.

0

There are 0 best solutions below