spring-boot注入service失败,求解

jack_jones 发布于 2015/12/06 14:16
阅读 11K+
收藏 0

目录结构

service注入

main类:

public static void main(String[] args) {
		Object[] obj = {Sample2Controller.class};
        //SpringApplication.run(obj, args);
        
        SpringApplication app = new SpringApplication(obj);
        app.setBannerMode(Banner.Mode.CONSOLE);
        app.addListeners(new TestListener());
        app.run(args);
	}



异常信息

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springboot.sample2.service.ISample2Service com.springboot.sample2.controller.Sample2Controller.sample2Service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.springboot.sample2.service.ISample2Service] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=sample2Service)}

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)

... 15 more

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.springboot.sample2.service.ISample2Service] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=sample2Service)}

at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)

... 17 more











加载中
0
kshine
kshine
用接口注入?
jack_jones
jack_jones
回复 @kshine : 求解
kshine
kshine
回复 @jack_jones : 实现类 注入依赖失败
jack_jones
jack_jones
回复 @kshine : @Service("sample2Service") public class Sample2ServiceImpl implements ISample2Service { 有实现类,名字叫"sample2Service"
kshine
kshine
回复 @jack_jones : 我知道有,spring是面向接口
jack_jones
jack_jones
接口有实现类
0
lyf_Tech
lyf_Tech
同问,楼主解决了吗
返回顶部
顶部