【发布时间】:2015-10-23 10:45:26
【问题描述】:
我正在尝试创建一个简单的 Spring Boot 应用程序,该应用程序将连接到 HSQLDB 并使用 User 表,但是在尝试启动它时我得到了这个。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
这里有整个控制台输出: http://pastebin.com/7HminjFL
我的文件是:
Application.java
@Configuration
@SpringBootApplication
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "hello")
@ComponentScan(basePackages = "hello")
@PropertySource({"classpath:application.properties"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
帐户.java
@Entity
@Table(name = "User", schema = "PUBLIC")
public class Account implements Serializable {
@Id
private Long id;
@Column(name = "Login", nullable = false)
private String login;
@Column(name = "Password", nullable = false)
private String password;
protected Account() {
// no-args constructor required by JPA spec
// this one is protected since it shouldn't be used directly
}
public Account(String login, String password) {
this.login = login;
this.password = password;
}
public String getLogin() {
return login;
}
public String getPassword() {
return password;
}
public void setLogin(String login) {
this.login = login;
return;
}
public void setPassword(String password) {
this.password = password;
return;
}
}
AccountRepository.java
public interface AccountRepository extends JpaRepository<Account, Long> {
Long countByLogin(String login);
}
application.properties
spring.datasource.url=jdbc:hsqldb:file:C:\DB\TestDB
spring.datasource.username=SA
spring.datasource.password=
spring.datasource.driver-class-name=org.hsqldb.jdbcDriver
【问题讨论】:
-
您正在使用 Spring Boot,然后使用您正在努力不使用的 Spring Boot。将您的
Application类移动到hello包中,删除除SpringBootApplication注释之外的所有注释。然后再次启动应用程序,如果仍然失败,请将堆栈跟踪添加到您的问题中。 -
我已经删除了注释(我只是在尝试解决这个问题时才添加的)并且同样的错误仍然存在,我已经将整个控制台输出粘贴到了 pastebin,因为它很大。
标签: java spring spring-boot hsqldb