2014-11-24 78 views
0

由於各種原因,我最終使用了spring boot 1.2.0 RC2。 因此,在spring boot1.1.8中正常運行的spring數據mongo應用程序現在有問題。沒有代碼被改變,除了彈簧啓動1.2.0 RC2。這是由於春季雲的快照版本移動到這個春季啓動版本。Spring數據中的類自動裝配問題Mongo存儲庫

repository類是如下

@Repository 
public interface OAuth2AccessTokenRepository extends MongoRepository<OAuth2AuthenticationAccessToken, String> { 

    public OAuth2AuthenticationAccessToken findByTokenId(String tokenId); 

    public OAuth2AuthenticationAccessToken findByRefreshToken(String refreshToken); 

    public OAuth2AuthenticationAccessToken findByAuthenticationId(String authenticationId); 

    public List<OAuth2AuthenticationAccessToken> findByClientIdAndUserName(String clientId, String userName); 

    public List<OAuth2AuthenticationAccessToken> findByClientId(String clientId); 
} 

這相當奏效的版本隆起之前,現在我看到這個在日誌中。

19:04:35.510 [main] DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: file [/Users/larrymitchell/rpilprojects/corerpilservicescomponents/channelMap/target/classes/com/cisco/services/rpil/mongo/repository/oauth2/OAuth2AccessTokenRepository.class] 

我確實有被認可的另一個蒙戈庫,但它被定義爲一個類實現

@Component 
public class ChannelMapRepository { ... } 

這一個是公認的(我把它定義爲一個實現類爲另一個問題的變通方法我有)。這個班被認可並且似乎工作正常。

19:04:35.513 [main] DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Identified candidate component class: file [/Users/larrymitchell/rpilprojects/corerpilservicescomponents/channelMap/target/classes/com/cisco/services/rpil/services/Microservice.class] 

任何人都有一個想法,爲什麼?我查了一下爲什麼組件掃描不起作用的各種原因,沒有任何東西可以解決我的問題。

+0

按預期工作,消息告訴你爲什麼。您的界面是一個界面,不會被組件掃描檢測到,它永遠不會(它在早期版本中沒有)。接口之一被Spring Data MongoDB檢測到並且行爲被添加。 – 2014-11-24 13:07:16

+0

如上所述,代碼中的唯一區別是彈簧引導的版本已更改。代碼在更改之前正常工作。看看他的指南,你會發現將存儲庫定義爲接口是可以接受的方式。實現類是由spring數據創建的:http://spring.io/guides/gs/accessing-data-mongodb/ – EvilJinious1 2014-11-24 14:01:29

+0

這就是我所說的......你使用的是Spring Boot,所以也要確保你使用的是Spring Boot爲了管理你的依賴關係,使用Spring Boot啓動器來引入你的依賴關係(在這種情況下,例如'spring-boot-starter-data-mongodb'),並且不要試圖繞過你自己的依賴關係。請添加你的pom,看看那裏(或者)是否缺少/不熟悉。 – 2014-11-24 14:06:52

回答