相关疑难解决方法(0)

Spring数据jpa-没有定义名为'entityManagerFactory'的bean; 注入自动连接的依赖项失败

我正在使用spring数据jpa,hibernate,mysql,tomcat7,maven开发应用程序,这就是创建错误.我想弄明白但是我失败了.

错误是在设置构造函数参数时无法解析对bean'entalManagerFactory'的引用; 没有定义名为'entityManagerFactory'的bean; 注入自动连接的依赖项失败

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initDbService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.wahid.cse.repository.RoleRepository org.wahid.cse.service.InitDbService.roleRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Cannot create inner bean '(inner bean)#c08f81' 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)#c08f81': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' …
Run Code Online (Sandbox Code Playgroud)

java jpa spring-mvc spring-data spring-data-jpa

62
推荐指数
5
解决办法
10万
查看次数

使用在类路径资源中定义的名称“entityManagerFactory”创建 bean 时出错(调用 init 方法失败)

当我尝试使用 hibernate 和 MySql 运行我的 spring-boot 项目时,出现以下错误。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-10 15:15:32.474 ERROR 12112 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.sliit.af.model.Course
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

java mysql hibernate jpa spring-boot

7
推荐指数
3
解决办法
5万
查看次数

没有名为“entityManagerFactory”的可用 bean

我创建了一个 Spring Boot 应用程序,并使用我想要执行的方法创建了一个类。将项目部署为 war 文件时,我从堆栈跟踪中收到错误。我想运行 TennisExecutor 类中的方法。

  • 没有名为“entityManagerFactory”的可用 bean
  • 创建名称为“(inner bean)#366583f9”的 bean 时出错:设置构造函数参数时无法解析对 bean“entityManagerFactory”的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为“entityManagerFactory”的bean可用

我将展示我的代码的一些部分:


@Configuration
@EnableAsync
@EnableScheduling
@ComponentScan(basePackages={"parser", "service", "processing", "automation"})
public class TennisExecutor extends SpringBootServletInitializer {

    @Autowired
    @Qualifier("tennisDataSource")
    private DataSource dataSource;

    @Autowired
    @Qualifier("tennisTm")
    PlatformTransactionManager transactionManager;

    @Autowired
    public ParseUpcomingMatchesFile parseUpcomingMatchesFile;

    @Autowired
    public ParseFinishedMatchesFile parseFinishedMatchesFile;

    @Autowired
    public PlayersProcessor playersProcessor;

    public TennisExecutor() {}

    @Scheduled(cron = "0 */2 * * * ?")
    public void executeTasks() throws IOException {

         parseUpcomingMatchesFile.parseMatchesFile(webDriver, new File(ConstantData.TOMORROW_UPCOMING_MATCHES_FILE_PATH));

     }

Run Code Online (Sandbox Code Playgroud)
@Configuration
@EnableJpaRepositories(basePackageClasses = {ParseUpcomingMatchesFile.class, ParseFinishedMatchesFile.class,
        PlayersProcessor.class}, entityManagerFactoryRef = "tennisEmf", …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa spring-boot

2
推荐指数
1
解决办法
9728
查看次数