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

spring注入失败问题,再不搞定我年都过不好了——不要让这100分荒废了
SSI框架研究了N久后,开始试着搭建简单的小功能,经历的什么找不到,那个不可以,这个定义不正确等等让人崩溃的异常后,终于是有个页面出来了,但我一点,你妹的有给了我个空指针异常!!!

折腾近两天了,发现该异常是由于spring依赖注入没有成功导致的,但看配置文件看了几百遍都没有看出错在哪里……
现贴出配置文件如下:
web.xml
XML code

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <!-- 配置Spring -->
     <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>
 
    <display-name>Struts Blank</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>



struts.xml
XML code

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.objectTypeDeterminer" value="notiger" />      
     <constant name="struts.objectFactory" value="spring" />   
     <constant name="struts.objectFactory.spring.autoWire" value="name" />  
     
    <package name="test" namespace="/test" extends="struts-default">
        
        <action name="select" class="test.User">
            <result>/test/result.jsp</result>
        </action>
        <!--
        <action name="insert" class="test.userDAO">
            <result>/test/result.jsp</result>
        </action>
        -->
    </package>
    
</struts>



applicationContext.xml
XML code

<?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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spri