2012-02-08 92 views
0

初始化應用程序後,這是蒙戈-config.xml中的一部分:CrudRepository爲null春

<mongo:repositories base-package="com.padmenu.web.repositories" 
    mongo-template-ref="mongoTemplate" query-lookup-strategy="create-if-not-  found"> 
    <mongo:repository id="userRepository" /> 
    <mongo:repository id="categoryRepository" /> 
</mongo:repositories> 

和裏面的applicationContext.xml:

<context:annotation-config /> 
<context:component-scan base-package="com.padmenu" /> 
<mvc:annotation-driven /> 
<import resource="mongo-config.xml" /> 

我CategoryRepository是

@Repository 
public interface CategoryRepository extends CrudRepository<Category, Long> { 

} 

我的CategoryBean是

public class CategoryBean implements Serializable { 

@Autowired 
CategoryRepository categoryRepository; 

在CategoryBean

@PostConstruct 
public void init() { 
    selectedCategory = new Category(); 
    categoryList = (List<Category>) categoryRepository.findAll(); 
    deleteCategoryList = new ArrayList<Category>(); 
    userLocaleList = new ArrayList<Locale>(); 
    userLocaleList.add(new Locale("tr")); 
    userLocaleList.add(new Locale("en")); 
    isForUpdate = false; 
} 

這裏categoryRepository的PostConstruct爲空。是什麼原因?爲什麼自動佈線不工作?

回答

0

加入 @Controller公共類CategoryBean實現Serializable解決了這個問題。