SpringブートMySQLを使用して非常に簡単なRESTサービスを作成しようとしています。しかし、エラーの周りを得ることができません。私は多くの検索を行いました。ほとんどの結果は、以下のコードがCRUD操作を実行できるベアボーンRESTサービスを構築するのに十分であることを示しました。スプリングブートMySQL RESTエラー - 'entityManagerFactory'/'emf'という名前のBeanが見つかりませんでした。
私はエラーに
***************************
APPLICATION FAILED TO START
***************************
Description:
Field repo in org.bluedolphin.spring.data.mysql.ActorController required a bean named 'entityManagerFactory' that could not be found.
Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
を得続けると私は、ファイルSpringDataMysqlApplicationで
@EnableJpaRepositories(basePackages="org.bluedolphin.spring.data.mysql", entityManagerFactoryRef="emf")
の行を追加したら、私は次のようなエラーに
***************************
APPLICATION FAILED TO START
***************************
Description:
Field repo in org.bluedolphin.spring.data.mysql.ActorController required a bean named 'emf' that could not be found.
Action:
Consider defining a bean named 'emf' in your configuration.
コード全体を取得を開始以下の通りです。
application.properties
#Server details
server.port=8180
# Replace with your connection string
spring.datasource.url=jdbc:mysql://localhost:3307/sakila
# Replace with your credentials
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driverClassName=com.mysql.jdbc.Driver
SpringDataMysqlApplication
@SpringBootApplication
@EnableJpaRepositories(basePackages="org.bluedolphin.spring.data.mysql", entityManagerFactoryRef="emf")
public class SpringDataMysqlApplication {
private static final Logger log = LoggerFactory.getLogger(SpringDataMysqlApplication.class);
public static void main(String[] args) {
SpringApplication.run(SpringDataMysqlApplication.class, args);
}
}
俳優
ActorRepository
public interface ActorRepository extends CrudRepository<Actor, Long> {
}
POM
<?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>org.bluedolphin.spring.data.mysql</groupId>
<artifactId>spring-data-mysql</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-data-mysql</name>
<description>spring-data-mysql</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
私はスプリング設定ファイルを持っておらず、アノテーションを使用してファイルを作成しています。 '@ EnableJpaRepositories'アノテーションを示唆しているが同じエラーとして追加しようとしました。 :( –
[このスレッドを見る](http://stackoverflow.com/questions/33074547/spring-boot-configure-entitymanager) – Satish