2017-03-29 7 views
1

私は、Springブート、Hibernate 5、およびMySQL DBを使用してWebアプリケーションを開発しています。 コンポーネントに「jpaTransactionManager」というBeanが見つかりませんでした。

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 
2017-03-29 09:36:59.862 ERROR 9312 --- [   main] o.s.b.d.LoggingFailureAnalysisReporter : 

*************************** 
APPLICATION FAILED TO START 
*************************** 

Description: 

A component required a bean named 'jpaTransactionManager' that could not be found. 


Action: 

Consider defining a bean named 'jpaTransactionManager' in your configuration. 
次のように私の設定は次のとおりです:私は、このようなメッセージを取得するアプリケーションを起動しようとすると

application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/test 
spring.datasource.username=root 
spring.datasource.password=root 
spring.datasource.driver-class-name=com.mysql.jdbc.Driver 

はのpom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>zapisano</groupId> 
    <artifactId>project-back-spring</artifactId> 
    <version>0.1.0</version> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
    </parent> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-thymeleaf</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.soundlibs</groupId> 
      <artifactId>mp3spi</artifactId> 
      <version>1.9.5-1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>5.2.9.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>5.2.3.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.projectlombok</groupId> 
      <artifactId>lombok</artifactId> 
      <version>1.16.16</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.34</version> 
     </dependency> 
    </dependencies> 

    <properties> 
     <java.version>1.8</java.version> 
    </properties> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

Application.java:

package core; 

import core.storage.StorageProperties; 
import core.storage.StorageService; 
import org.springframework.boot.CommandLineRunner; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.context.properties.EnableConfigurationProperties; 
import org.springframework.context.annotation.Bean; 

@SpringBootApplication 
@EnableConfigurationProperties(StorageProperties.class) 
public class Application { 

    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args); 
    } 

    @Bean 
    CommandLineRunner init(StorageService storageService) { 
     return (args) -> { 
      storageService.deleteAll(); 
      storageService.init(); 
     }; 
    } 
} 

「jpaTransactionManager」という名前のBeanを明示的に宣言する方法はほとんどありません。 .xmlまたはapplication.propertiesにSpringの設定があります。

私はその場合の3つの質問を持っている:

  • 「jpaTransactionManager」という名前のBeanを宣言するための最良の方法は何ですか?
  • 自動的に行うことはできますか?
  • また、.x​​mlを使用しないでください。

答えて

2

私はそれが自動的に行うことができるか分からない、私はあなたがそれを宣言する必要があると思います。 jpaTransactionManagerを定義できる別の@Configuration Bean(xml configを必要としない)に設定するのがよいでしょう。

このような例はhereです。

関連する問題