NoSuchBeanDefinitionException: No qualifying bean of type [Repository] found for dependency: expected at least 1 bean which qualifies as autowire

倾然丶 夕夏残阳落幕 提交于 2019-11-29 12:52:44

Your own implementation of the WebApplicationInitializer and the implementation extending AbstractAnnotationConfigDispatcherServletInitializer are different. They behave different and that is because you aren't registering your custom ApplicationContextInitializer. How to register the ApplicationContextInitializer is explained in the javadoc (notice the 2 methods to set a collection of ApplicationContextInitializers.).

public class AppInitialzer extends AbstractAnnotationConfigDispatcherServletInitializer {

    ...    

    protected ApplicationContextInitializer<?>[] getRootApplicationContextInitializers() {
        return new ApplicationContextInitializer[] { new SpringAppContInit() } ;
    }
}

However that ApplicationContextInitializer doesn't really add anything that cannot already be done by simply setting an environment or system property.

spring.profiles.active=SQLDev

When you do that you don't need that init.

I also strongly believe that your @EnableJpaRepositories is on the wrong class, the fact that you want to enable those shouldn't depend on your profile.

@ComponentScan(basePackages = "base package") @EntityScan(basePackages ="base package") @EnableJpaRepositories(basePackages = "base package")

use this annotation and if you are using spring-data-jpa then extends CrudRepository or PagingAndSortingRepository instead of JpaRepository.And in TestController give autowired like this :

@Autowired(required = true) CategoryRepository catRepo; Also check in Category whether the id of type BigDecimal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!