我正在运行一个应该使用hibernate连接到数据库的spring启动应用程序,但是我收到以下异常:Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
我的application.properties
server.port=9000
spring.datasource.url=jdbc:mysql://localhost/Users
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
这是我的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<properties>
<spring.boot.version>1.1.8.RELEASE</spring.boot.version>
<start.class>com.server.boot.Starter</start.class>
<spring.core.version>4.0.6.RELEASE</spring.core.version>
<log4j.version>1.2.17</log4j.version>
<tomcat.version>8.0.8</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.core.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
</dependencies>
我的配置类:
@Configuration
@ComponentScan({"com.server"})
@EnableAutoConfiguration
public class Starter {
public static void main(String[] args){
SpringApplication.run(Starter.class,args);
System.out.println("started application");
}
@Bean
public LoginController loginController(){
return new LoginController();
}
}
我的控制员:
@Service
@Transactional
@RestController
@RequestMapping("/user")
public class LoginController {
@PersistenceContext
private EntityManager entityManager;
@RequestMapping(value="/login",method=RequestMethod.POST)
public String login(@RequestParam(value="username",required=true) String username,
@RequestParam(value="password",required=true) String password){
return "Tried to login as "+username + " where em is "+entityManager;
}
}
这是什么原因?
进一步研究
我相信这个问题的答案org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set解决了它