[英]Spring Data repository Auto injection failing
我正在嘗試將項目升級到Spring 5.0.6和Spring Data 2.0.6,我們正在使用WebSphere管理的JPA 2.1
創建Spring上下文時獲得以下異常:
[5/29/18 6:30:41:929 CDT] 00000052 SystemOut O 06:30:41.876 [默認值:5]錯誤org.springframework.web.context.ContextLoader-上下文初始化失敗org.springframework.beans.factory。 UnsatisfiedDependencyException:創建名稱為'userService'的bean時出錯:通過字段'userRepository'表示的不滿足的依賴關系; 嵌套的異常是org.springframework.beans.factory.NoSuchBeanDefinitionException:沒有類型為'com.mmm.arc.dao.UserRepository'的合格Bean:期望至少有1個合格為自動裝配候選的Bean。
...
@Transactional(propagation = Propagation.REQUIRED )
public class UserServiceImpl implements UserService, UserDetailsService {
@PersistenceContext
private EntityManager em;
@Autowired
UserRepository userRepository;
}
public interface UserRepository extends JpaRepository<User, String>, JpaSpecificationExecutor< User >,UserRepositoryCustom{
}
public class UserRepositoryImpl implements UserRepositoryCustom{
@PersistenceContext
EntityManager em;
-----------methods
}
在架構中,我沒有提到任何春季版本
<jpa:repositories base-package="repo class package" /><bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistance unit name"/>
<property name="dataSource" ref="dataSource"/>
</bean>
我們有單獨的persistence.xml文件來映射所有完全基於注釋的實體
您的bean UserRepositoryImpl
沒有實現interface UserRepository
,這是UserServiceImpl
使用的類型。 因此,我認為實際上沒有在任何地方創建UserRepository
實例。
也許您打算讓implement UserRespository
代替UserRepositoryImpl
來implement UserRespository
UserRepositoryCustom
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.