rj2*_*700 2 hibernate spring-mvc spring-data
我收到以下错误(从我相信,Dao层 - 但我可能会读错了).
我现在有一个Spring启动应用程序,创建一个数据库架构.这些表正在正确创建,但是当我尝试添加Dao和DaoImpl文件时,它会崩溃,并显示以下错误消息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field session in xx.dao.ParkingSpaceDaoImpl required a bean of type 'org.hibernate.SessionFactory' that could not be found.
Action:
Consider defining a bean of type 'org.hibernate.SessionFactory' in your configuration.
Run Code Online (Sandbox Code Playgroud)
在我的DaoImpl文件中,我有:
@Repository
public class xxDaoImpl implements xxDao {
@Autowired
private SessionFactory session;
Run Code Online (Sandbox Code Playgroud)
以下是我的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>xx.xx</groupId>
<artifactId>xxx</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/>
</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-jdbc</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>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
有没有人知道我如何解决这个问题?请让我知道,谢谢.
所以我找到了适合我的解决方案.如果您正在使用配置.xml文件,Mathias可能是正确的.但对于那些使用application.properties文件的用户,需要将此行添加到配置类或主应用程序类中:
@Bean
public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf){
return hemf.getSessionFactory();
}
Run Code Online (Sandbox Code Playgroud)
完成后,将此行添加到application.properties文件中:
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
Run Code Online (Sandbox Code Playgroud)
这个解决方案对我有用.以下是我能够解决的其他参考资料:
http://www.ekiras.com/2016/02/how-to-use-configure-session-factory-bean-springboot.html
Spring Boot - Hibernate SessionFactory的句柄
| 归档时间: |
|
| 查看次数: |
8946 次 |
| 最近记录: |