日期:2014-05-17  浏览次数:20882 次

Spring初始化问题
在一个web.xml中添加了
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
tomcat启动正常,但是到用到需要注入的类的地方就会报错:
javax.naming.NameNotFoundException: Name userService is not bound in this Context
userService是我在servlet中想让spring容器给我自动注入的

------解决方案--------------------
javax.naming.NameNotFoundException: Name userService is not bound in this Context
userService是我在servlet中想让spring容器给我自动注入的

你的意思是你想spring帮你把userService注入到你的servlet中去,是这个意思吧。那你的的servlet也要交给spring来管理了。不过,在实际使用中,应该不会有要spring去管理servlet的情况吧。