当前位置: 代码迷 >> J2EE >> spring @Resource 注入有关问题
  详细解决方案

spring @Resource 注入有关问题

热度:383   发布时间:2016-04-19 22:57:54.0
spring @Resource 注入问题
servlet引入@Resource报错:
javax.naming.NameNotFoundException: Name testService is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:276)
at org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:187)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1153)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
代码如下:
servlet :
public class testServlet extends HttpServlet {
private static final long serialVersionUID = -4732854077814547321L;
@Resource(name = TestService.IOC_BEAN_ID)
private TestService test1;
service:
public interface TestService {
public static final String IOC_BEAN_ID = "testService";
public Map getSysdate();
}

@Service(TestService.IOC_BEAN_ID)
public class TestServiceImpl extends BaseService implements TestService{

public Map getSysdate(){
Map<String,Object> sysdateMap = (Map<String, Object>) ibatisClient.queryForObject("test.test", "");
return sysdateMap;
}
}
spring 配置:
<context:annotation-config />
<context:component-scan base-package="com.test" />
------解决方案--------------------
NameNotFoundException: Name testService is not bound in this Context
"TestService"是不是这个类没有注释的原因啊?
  相关解决方案