2017-09-13 40 views
6

Bắt đầu xây dựng một ( đầu tiên) ứng dụng khởi động mùa xuân và đây là lớp học chính khởi động mùa xuân của tôi (Full code on github)mùa xuân khởi động (mysql với JPA): Không đậu có tên là 'entityManagerFactory' sẵn

@EnableAutoConfiguration 
@SpringBootApplication 
public class Application { 

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

Và đây là 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>com.example</groupId> 
    <artifactId>demo</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>demo</name> 
    <description>Demo project for Spring Boot</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.6.RELEASE</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-jersey</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <scope>runtime</scope> 
     </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> 


</project> 

Tôi tiếp tục gặp lỗi dưới đây. Những gì tôi thiếu để thêm? Tại sao tôi cần phải thêm một bean bean có tên 'entityManagerFactory' ?? và nó là cần thiết ngay cả sau khi sử dụng khởi động mùa xuân ??

repo của tôi trông như thế này nếu đó là vấn đề

public interface RegistrationRepo extends JpaRepository<User, Long> { 
    User findByEmail(String email); 
} 

. ____ _ __ _ _ /\/' __ _ () _ __ __ _ \ \ \ \ (() _ | '_ |' | |'/`| \ \ \ \ \/) | | ) | | | | | || ( | |)))) '| ____ | . | | | | | | __, |//// ========= | _ | ============== | ___/=///_/ :: Khởi động mùa xuân :: (v1.5.6.RELEASE)

2017-09-13 12: 48: 38.808 INFO 15361 --- [main] com.rightlink.RightLinkỨng dụng: Bắt đầu RightLinkỨng dụng trên Admins-MacBook-Pro.local với PID 15361 (/ Người dùng /sureshatta/Documents/workspace-sts-3.9.0.RELEASE/RightLink/target/classes được bắt đầu bởi sureshatta trong /Users/sureshatta/Documents/workspace-sts-3.9.0.RELEASE/RightLink) 2017-09-13 12 : 48: 38.811 INFO 15361 --- [main] com.rightlink.RightLinkApplication: Không có hồ sơ hoạt động nào được đặt, quay trở lại hồ sơ mặc định: mặc định 2017-09-13 12: 48: 38.865 INFO 15361 --- [main] ationConfigEmbeddedWebApplicationContext : Làm mới org.springframewor k.boot[email protected]120d6fe6: ngày khởi động [Wed Sep 13 12:48:38 IST 2017]; gốc của hệ thống phân cấp ngữ cảnh 2017-09-13 12: 48: 40.380 INFO 15361 --- [main] sbcetTomcatEmbeddedServletContainer: Tomcat được khởi tạo với (các) cổng: 8181 (http) 2017-09-13 12: 48: 40.402 INFO 15361 --- [chính] o.apache.catalina.core.StandardService: Bắt đầu dịch vụ [Tomcat] 2017-09-13 12: 48: 40.403 INFO 15361 --- [main] org.apache.catalina.core.StandardEngine : Khởi động Servlet Engine: Apache Tomcat/8.5.16 2017-09-13 12: 48: 40.566 INFO 15361 --- [ost-startStop-1] oaccC [Tomcat]. [Localhost]. [/]: Khởi tạo Spring nhúng WebApplicationContext 2017-09-13 12: 48: 40.567 INFO 15361 --- [ost-startStop-1] osweb.context.ContextLoader: Root WebApplicationContext: khởi tạo hoàn thành trong 1705 ms 2017-09-13 12: 48: 40.743 INFO 15361 --- [ost-startStop-1] osbwservlet.ServletRegistratio nBean: Lập bản đồ servlet: 'dispatcherServlet' đến [/] 2017-09-13 12: 48: 40.752 INFO 15361 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean: Bộ lọc ánh xạ: 'characterEncodingFilter' to: [/ ] 2017-09-13 12: 48: 40.753 INFO 15361 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean: Bộ lọc ánh xạ: 'hiddenHttpMethodFilter' thành: [/] 2017-09-13 12: 48: 40.753 INFO 15361 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean: Bộ lọc ánh xạ: 'httpPutFormContentFilter' thành: [/ ] 2017-09-13 12: 48: 40.753 INFO 15361 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean: Bộ lọc ánh xạ: 'requestContextFilter' tới: [/] 2017-09-13 12: 48: 40.844 WARN 15361 --- [main] ationConfigEmbeddedWebApplicationContext: Ngoại lệ gặp phải trong khi khởi tạo ngữ cảnh - hủy cố gắng làm mới: org.springframework.beans.factory.UnsatisfiedDependencyException: Lỗi tạo bean có tên 'registerController': Phụ thuộc không thỏa mãn được thể hiện qua trường 'regServices'; ngoại lệ lồng nhau là org.springframework.beans.factory.UnsatisfiedDependencyException: Lỗi tạo bean với tên 'regService': Phụ thuộc không thỏa mãn được thể hiện thông qua trường 'registrationRepo'; ngoại lệ lồng nhau là org.springframework.beans.factory.BeanCreationException: Lỗi khi tạo bean với tên 'registrationRepo': Không thể tạo bean bên trong '(bean bên trong) # 43c67247' của kiểu [org.springframework.orm.jpa.SharedEntityManagerCreator] trong khi thiết lập bean property 'entityManager'; ngoại lệ lồng nhau là org.springframework.beans.factory.BeanCreationException: Lỗi tạo bean với tên '(bean bên trong) # 43c67247': Không thể giải quyết tham chiếu đến bean 'entityManagerFactory' trong khi thiết lập đối số hàm tạo; ngoại lệ lồng nhau là org.springframework.beans.factory.NoSuchBeanDefinitionException: Không có bean có tên 'entityManagerFactory' có sẵn 2017-09-13 12: 48: 40.849 INFO 15361 --- [main] o.apache.catalina.core.StandardService: Dừng dịch vụ [Tomcat] 2017-09-13 12: 48: 40.903 INFO 15361 --- [chính] utoConfigurationReportLoggingInitializer:

Lỗi khi khởi chạy ApplicationContext. Để hiển thị báo cáo cấu hình tự động, hãy chạy lại ứng dụng của bạn đã bật 'gỡ lỗi'. 2017/09/13 12: 48: 40,975 LỖI 15361 --- [chính] osbdLoggingFailureAnalysisReporter:


ĐƠN FAILED ĐỂ BẮT ĐẦU


Mô tả:

Dòng registrationRepo trong com .rightlink.services.RegistrationService yêu cầu một bean có tên 'entityManagerFactory' không thể tìm thấy.

Hành động:

Xem xét xác định bean có tên 'entityManagerFactory' trong cấu hình của bạn.

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 
spring.jpa.hibernate.ddl-auto=update 
server.port=8181 

Cố gắng thêm @Repository chú thích cho repo, và cũng nói thêm @enableJpaRepositories chú thích trong lớp học chính. Không có gì giúp.

+0

Mùa xuân (chính xác hơn JPA) cần biết nơi thực thểManagerFactory của bạn và sau đó sử dụng nó để quản lý người quản lý thực thể. Tham khảo https: //docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html – spiritwalker

+0

@spiritwalker Nhưng tôi không cần nguồn dữ liệu tùy chỉnh, muốn chuyển sang mặc định. –

+0

@ ꜱᴜʀᴇꜱʜᴀᴛᴛᴀ bạn có chắc đó là thông điệp tường trình duy nhất bạn có? – MangEngkus

Trả lời

2

Vấn đề không phải với phiên bản khởi động trực tiếp và các vấn đề là với lọ ngủ đông lạnh. Kể từ khi tôi thêm hỗ trợ JPA cho dự án, khởi động nội bộ bằng cách sử dụng (??) Hibernate như là một JPA thực hiện và cố gắng sử dụng (??) những lọ. Vì repo địa phương của tôi đã bị hỏng hibernate-entity-* jars, lỗi lạ này xảy ra.

comment in the code của họ xác nhận rằng họ sử dụng chế độ ngủ đông trong nội bộ.

<!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) --> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 

Đã xóa thư mục ngủ đông hoàn chỉnh khỏi kho lưu trữ cục bộ maven và nowit của tôi có vẻ ổn.

+0

Ứng dụng bạn đã chia sẻ hoạt động cho tôi. Cả hai đều có '1.3.1.RELEASE' và' 1.5.6.RELEASE'. Tôi tin rằng một bình có thể đã bị hỏng khi bạn tải xuống 1.5.6 lần đầu tiên. Chuyển sang đó và chạy 'mvn dependency: purge-local-repository' để loại bỏ jar bị hỏng. –

+0

Yeap Tôi cũng có một ứng dụng khởi động mùa xuân với '1.5.6.RELEASE' và nó hoạt động ra khỏi hộp với cùng một thiết lập như của bạn. – pleft

Các vấn đề liên quan