将spring-boot-starter-security添加到Spring Boot应用程序会导致错误“entityManagerFactory”或“persistenceUnitName”是必需的

时间:2013-12-08 05:43:49

标签: spring spring-boot spring-security spring-orm

我使用Spring Initializr(http://start.spring.io/)创建了一个Spring Boot(0.5.0.BUILD-SNAPSHOT)应用程序,我添加了一个@RestController,一个CrudRepository接口和一个@Entity类 - 没有复杂。 My 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依赖项时,应用程序运行正常,但未启用安全性。错误是什么意思?该应用程序已经使用了JPA和Hibernate而没有启用Spring Security。

1 个答案:

答案 0 :(得分:0)

有一个bug there。事业真的非常技术性,与春天的内部BeanFactory有关。看看Github问题,如果你想了解更多,但可能你应该只是刷新你的快照依赖项并得到修复。