在一个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容器给我自动注入的

解决方案 »

  1.   

    看下applicationContext.xml写的对不对
      

  2.   

    你说对 发出来大家帮你看下啊! 都对  怎么会有问题呢?   你看下applicationContext 的 bean id 是userService吗?  如果是把自动装配改成 bytype 
      

  3.   

    set,get方法写了没有,不然注入不上
      

  4.   

    lz说的是使用 @Autowired 吗?
    如果是的话,可以看下这链接,我也是跟着它搞好@Autowired的
    http://www.ibm.com/developerworks/cn/java/j-lo-spring25-ioc/
      

  5.   

    javax.naming.NameNotFoundException: Name userService is not bound in this Context
    userService是我在servlet中想让spring容器给我自动注入的你的意思是你想spring帮你把userService注入到你的servlet中去,是这个意思吧。那你的的servlet也要交给spring来管理了。不过,在实际使用中,应该不会有要spring去管理servlet的情况吧。
      

  6.   

    应该是在servlet中注入的问题,我试了下吧struts的action交给spring来管理,就没有问题了。servlet是由servlet容器来管理的,又交给spring来管理好像就不行了