整合代码如下,但是出现实例化Action错误!
bean代码
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/student">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- if use the hibernate.cfg.xml as dataSource configuration, cancel the annotations -->
<!-- remove other properties and dataSource bean. -->
<!-- 
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
-->
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/gf/orm/Stuinfo.hbm.xml</value>
</list>
</property>
</bean> <bean name="updateAct" class="com.gf.Action.UpdateMessageAction"
scope="prototype">
<property name="Service" ref="Service"></property>
</bean>
<bean name="findAct" class="com.gf.Action.FindMessageAction"
scope="prototype">
<property name="Service" ref="Service"></property>
</bean>
<bean name="lookAct" class="com.gf.Action.LookMessageAction"
scope="prototype">
<property name="Service" ref="Service"></property>
</bean>
<bean name="addAct" class="com.gf.Action.AddMessageAction"
scope="prototype">
<property name="Service" ref="Service"></property>
</bean>
<bean name="delAct" class="com.gf.Action.DeleteMessageAction"
scope="prototype">
<property name="Service" ref="Service"></property>
</bean>
<bean id="Service" class="com.gf.studentservice.studentservice">
<property name="dao" ref="dao"></property>
</bean> <bean name="dao" class="com.gf.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

</beans>struts代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
 "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <constant name="struts.objectFactory" value="spring"/>
    <package name="myApp" extends="struts-default">
        <action name="lookMessageAction" class="lookAct">
            <result name="success">
                lookMessage.jsp
            </result>
            <result name="input">
                /index.jsp
            </result>
        </action>
        <action name="addMessageAction" class="addAct">
            <result name="success" type="chain">lookMessageAction</result>
            <result name="input">
                /addMessage.jsp
            </result>
        </action>
<action name="findMessageAction" class="findAct">
            <result name="success" >
                /updateMessage.jsp
            </result>
            <result name="input">
                /findMessage.jsp
            </result>
        </action>
<action name="updateMessageAction" class="updateAct">
            <result name="success" >
                /lookMessage.jsp
            </result>
            <result name="input">
                /updateMessage.jsp
            </result>
        </action>
<action name="deleteMessageAction" class="delAct">
            <result name="success" >
                /lookMessage.jsp
            </result>
            <result name="input">
                /deleteMessage.jsp
            </result>
        </action>
    </package>
</struts>web.xml 代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
           
        <param-name>
            contextConfigLocation
        </param-name>
           
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
         
    </context-param>
    <!-- Listener contextConfigLocation -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    
    <filter>
        <filter-name>
            struts2
        </filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>
            struts2
        </filter-name>
        <url-pattern>
            /*
        </url-pattern>
    </filter-mapping>
    
</web-app>

解决方案 »

  1.   

    http://blog.csdn.net/peng_hao1988/article/details/7417634
    给个例子吧,代码太多了。
      

  2.   

    给你一个demo
    http://download.csdn.net/detail/s478853630/4382009
    或许能帮你
      

  3.   

    看不到错误,不知道问题所在。
    但是,关系到Action的话,我发现,你没配置:namespace。这个不是关键,但是,要小心它给你带来的麻烦。
      

  4.   

    错误信息是 HTTP Status 500 - Unable to instantiate Action, lookAct, defined for 'lookMessageAction' in namespace '/'Error creating bean with name 'lookAct' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Service' of bean class [com.gf.Action.LookMessageAction]: Bean property 'Service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?--------------------------------------------------------------------------------type Exception reportmessage Unable to instantiate Action, lookAct, defined for 'lookMessageAction' in namespace '/'Error creating bean with name 'lookAct' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Service' of bean class [com.gf.Action.LookMessageAction]: Bean property 'Service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?description The server encountered an internal error (Unable to instantiate Action, lookAct, defined for 'lookMessageAction' in namespace '/'Error creating bean with name 'lookAct' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Service' of bean class [com.gf.Action.LookMessageAction]: Bean property 'Service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?) that prevented it from fulfilling this request.exception Unable to instantiate Action, lookAct,  defined for 'lookMessageAction' in namespace '/'Error creating bean with name 'lookAct' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Service' of bean class [com.gf.Action.LookMessageAction]: Bean property 'Service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    root cause org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lookAct' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'Service' of bean class [com.gf.Action.LookMessageAction]: Bean property 'Service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:141)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    root cause org.springframework.beans.NotWritablePropertyException: Invalid property 'Service' of bean class [com.gf.Action.LookMessageAction]: Bean property 'Service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1024)
    org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:900)
    org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
    org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:141)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.
    --------------------------------------------------------------------------------Apache Tomcat/7.0.29
      

  5.   

    打开页面进入
    <html>
    <body>.....
    .....<s:a href="lookMessageAction">.....
    </body>.....
    <html>
    Action 代码public class LookMessageAction extends ActionSupport {
    private studentservice<Stuinfo> Service;
    private Stuinfo stuinfo; public Stuinfo getStuinfo() {
    return stuinfo;
    } public void setStuinfo(Stuinfo stuinfo) {
    this.stuinfo = stuinfo;
    } private HttpServletRequest request;
    private String message = "input"; public String execute() throws Exception {
    request = ServletActionContext.getRequest(); List list = Service.queryStudent(null, null);
    request.getSession().setAttribute("count", list.size());
    request.getSession().setAttribute("allInfo", list);
    message = "success";
    return message;
    }
    }
      

  6.   

    Action的service没有 get set方法
      

  7.   

    lookMessageAction你这个action创建不了,是由于你配置有问题。service没有注入好。