JAR-SPRING@autowired

JAR-SPRING@autowired,spring,jar,Spring,Jar,我创建了一个java归档,并希望将其集成到我的应用程序中 关于我的主要申请: ApplicationContext.xml: <context:component-scan base-package="com.test.chomage" /> 在我的java存档上: appConfig.java @Configuration @ComponentScan("com.test.jarPatrimoine") public class AppConfig { } Organizat

我创建了一个java归档,并希望将其集成到我的应用程序中

关于我的主要申请:

ApplicationContext.xml:

<context:component-scan base-package="com.test.chomage" />
在我的java存档上:

appConfig.java

@Configuration
@ComponentScan("com.test.jarPatrimoine")
public class AppConfig {

}
OrganizationService.java

public interface OrganisationService {
  //Functions
}
OrganizationServiceImpl.java

@Service
@Transactional
public class OrganisationServiceImpl implements OrganisationService 
  //Functions
}
启动tomcat服务器时,出现下一个错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'chomageController': 
Unsatisfied dependency expressed through field 'organisationService';
nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 
'com.test.jarPatrimoine.service.OrganisationService' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency 
annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
你能帮我吗


谢谢

还有其他课程实施组织服务吗?如果是这样,您需要添加@Qualifier注释来注入正确的实现

@Autowire
     @Qualifier("thequalifyingbean") 
     OrganisationService organisationService;

也可以将@Controller用于控制器类,而不是@Component

Spring正在查找
com.vnf.jarPatrimoine.service.organizationservice
,但扫描配置为
@ComponentScan(“com.test.jarPatrimoine”)
。您可能必须更改它。

对不起,这是我帖子上的一个错误。我的扫描和我的包是一样的。我只是观察了@qualifier是如何工作的,它是当我们有几个类实现一个接口时使用的注释,我们希望使用这个接口注入依赖项。在我的例子中,我只有一个实现接口的类。为什么将控制器类命名为@component?它不应该是@Controller吗?是的,它更好,但是@component是任何Spring管理组件的通用原型?为了保持逻辑性,我将改变它。
@Autowire
     @Qualifier("thequalifyingbean") 
     OrganisationService organisationService;