context 컴포넌트 검색이 구성되어있는 한 @Component
주석을 사용하여 스프링 빈을 생성 할 수 있습니까? 자바 6xml bean 정의가없는 스프링 컴포넌트 감지
내 테스트 케이스를 봄 3.0.5를 사용
은 다음과 같습니다
@ContextConfiguration(locations={"classpath:spring-bean.xml"})
public class ServerServiceUnitTest extends AbstractJUnit4SpringContextTests {
@Autowired
private ServerService serverService;
@Test
public void test_server_service() throws Exception {
serverService.doSomething();
//additional test code here
}
}
spring-bean.xml
파일에는 다음이 포함
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
</beans>
내 클래스가 나는 콩이되고 싶어요 :
@Component("ServerService")
public class ServerServiceImpl implements ServerService {
private static final String SERVER_NAME = "test.nowhere.com";
//method definitions.....'
}
스프링이 ServerService
빈을 인스턴스화하고 자동 와이어 링을 수행하기에 충분하지 않아야합니까?
I 얻을 오류 : org.springframework.beans.factory.NoSuchBeanDefinitionException :
자격에 의한 것으로, 적어도 1 빈 : 유형 일치 빈이 [serversystem.ServerService] 의존성 발견 이 종속성에 대한 autowire 후보로. 종속성 주석 : {@ org.springframework.beans.factory.annotation.Autowired (필수 = true)}
나는 뭔가 간단하다고 생각합니다.
Perfect. 감사! – wadesworld