我使用 Spring Initializr ( http://start.spring.io/ )创建了一个 Spring Boot (0.5.0.BUILD-SNAPSHOT) 应用程序,并添加了一个 @RestController、一个 CrudRepository 接口和一个 @Entity 类- 没什么复杂的。我的 Maven POM 包含以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
Application 类包含默认值:
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
简单的应用程序运行没有错误,但我决定将 Spring Security 添加到 POM 以保护管理端点:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
现在应用程序无法启动,我得到以下信息:
java.lang.IllegalArgumentException:需要“entityManagerFactory”或“persistenceUnitName”
Caused by: java.lang.IllegalArgumentException: 'entityManagerFactory' or 'persistenceUnitName' is required
at org.springframework.orm.jpa.JpaTransactionManager.afterPropertiesSet(JpaTransactionManager.java:304)
at org.springframework.orm.jpa.JpaTransactionManager.<init>(JpaTransactionManager.java:141)
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.transactionManager(JpaBaseConfiguration.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 18 more
当我删除 spring-boot-starter-security 依赖项时,应用程序运行良好但没有启用安全性。错误是什么意思?该应用程序已经在没有启用 Spring Security 的情况下使用 JPA 和 Hibernate。