2013-12-08 40 views
0

我使用Spring Initializr(http://start.spring.io/)和I創建了一個Spring Boot(0.5.0.BUILD-SNAPSHOT)添加了一個@RestController,一個CrudRepository接口和一個@Entity類 - 沒有什麼複雜的。我的Maven POM包含以下依存關係:爲Spring Boot應用程序添加spring-boot-starter-security會導致錯誤'entityManagerFactory'或'persistenceUnitName'

<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); 
    } 
} 

簡單的應用程序運行沒有錯誤,但我還是決定春季安全添加到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 Security的情況下使用JPA和Hibernate。

+0

它看起來像是在安全配置中的某些bean可能迫使某些JPA依賴關係的早期實例化。我從來沒有看到過這個具體問題,並且我們已經在JPA和安全性方面開發了很多應用程序。可能有一個我們以前從未見過的奇怪的排序問題。我會看看,看看我是否可以重現它。任何有答案的人都可以隨時發表評論。 –

回答

0

有一個bug there。這個原因真的非常深入技術,並且與Spring的內部組件BeanFactory有關。看看Github的問題,如果你想得到更多的理解,但可能你應該能夠刷新你的快照依賴關係並獲得修復。

相關問題