先说我配置,增加一个模块后1.我要把STRUTS ACTION托管给SPRING ,那样我必须在STRUTS中吧ACTIONG的TYPE改成“org.springframework.web.struts.DelegatingActionProxy”
在Spring的配置文件里增加 BEAN配置,并注入Service2.把SERVICE配置进SPRING文件,并注入DAO
3,然后分别要提取DAO SERVICE接口,感觉很麻烦。以上我都是手工配置,各位有什么办法没 (比如用 Myeclipse),这样感觉太麻烦了,一有模块我就得重复一次  

解决方案 »

  1.   

    web.xml,struts,spring中都有可视化的界面,我们没有必要再代码中配置,很难达到全部正确,不过现在如果是智能的配置,我还不知道。
      

  2.   

    你也可以用Spring的注解技术,这样只需在类文件中进行注解,不必另外写配置文件。
      

  3.   

    在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>
      

  4.   

    恩? 那样就可以不用配置STRUTS 文件type了么?
      

  5.   

    <controller> 
    <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/> 
    </controller>
    这种我知道 但我想用CONTROLLER 做其它的事····
      

  6.   

    <controller
    processorClass="org.springframework.web.struts.AutowiringRequestProcessor">
    </controller>
    在struts里面配置这个就不用配置type了
      

  7.   

    spring2.5版本后,可以通过注解注入了吧
      

  8.   

    注解还是比较方便的,最起码spring配置文件看着非常干净
      

  9.   

    不用这么麻烦吧
    看看我以前用的
    struts.xml<?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.1.dtd">
    <struts> <package name="gunct" extends="struts-default" namespace="">

    <global-results>
    <result name="all">/error.jsp</result>
    </global-results> <global-exception-mappings>
    <exception-mapping result="all"
    exception="java.lang.Exception">
    </exception-mapping>
    </global-exception-mappings>



    <action name="*pro" class="pro" method="{1}pro">
    <result name="success">pro_list.jsp</result>
    <result name="show">pro_show.jsp</result>
    <result name="error">/error.jsp</result>
    <result name="update">/admin/pro_update.jsp</result>
    </action> <action name="*news" class="news" method="{1}news">
    <result name="success">news_list.jsp</result>
    <result name="error">/admin/error.jsp</result>
    <result name="update">/admin/news_update.jsp</result>
    <result name="show" type="dispatcher">
    /news_show.jsp
    </result>
    </action> <action name="*message" class="message" method="{1}message">
    <result name="success">/dispatch.jsp</result>
    <result name="error">/error.jsp</result>
    <result name="list">/admin/msg_list.jsp</result>
    <result name="show">/admin/msg_show.jsp</result>
    </action> <action name="*investor" class="investor"
    method="{1}investor">
    <result name="success">/dispatch.jsp</result>
    <result name="error">/error.jsp</result>
    <result name="list">/admin/investor_list.jsp</result>
    <result name="show">/admin/investor_show.jsp</result>
    </action>
    <action name="admin*" class="admin" method="admin{1}">
    <result name="success" type="redirect">
    /admin/admin.html
    </result>
    <result name="error">/admin/error.jsp</result>
    <result type="redirect" name="login">/login.jsp</result>
    </action>
    </package>
    </struts>application.xml<?xml version="1.0" encoding="utf-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 定义数据源Bean,使用C3P0数据源实现 -->
    <bean id="dataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <!-- 指定连接数据库的驱动 -->
    <property name="driverClass"
    value="com.mysql.jdbc.Driver" />
    <!-- 指定连接数据库的URL -->
    <!-- property name="jdbcUrl"
    value="jdbc:sqlserver://localhost;databaseName=gunctweb" /-->
    <property name="jdbcUrl"
    value="jdbc:mysql://gunct.cn/xxx" />
    <!-- 指定连接数据库的用户名 -->
    <property name="user" value="xxxx" />
    <!-- 指定连接数据库的密码 -->
    <property name="password" value="xxx" />
    <!-- 指定连接数据库连接池的最大连接数 -->
    <property name="maxPoolSize" value="20" />
    <!-- 指定连接数据库连接池的最小连接数 -->
    <property name="minPoolSize" value="1" />
    <!-- 指定连接数据库连接池的初始化连接数 -->
    <property name="initialPoolSize" value="1" />
    <!-- 指定连接数据库连接池的连接的最大空闲时间 -->
    <property name="maxIdleTime" value="20" />
    </bean> <!--定义了Hibernate的SessionFactory -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
    <list>
    <value>Project.hbm.xml</value>
    <value>News.hbm.xml</value>
    <value>Message.hbm.xml</value>
    <value>Investor.hbm.xml</value>
    <value>Admin.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.jdbc.batch_size">20</prop>
    </props>
    </property>
    </bean> <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean> <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <!--  事务拦截器bean需要依赖注入一个事务管理器 -->
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
    <!--  下面定义事务传播属性-->
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean> <!-- 配置project组件 -->
    <bean id="proDao" class="com.gunct.gunctweb.daoImpl.ProDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate" />
    </bean> <bean id="proMgr"
    class="com.gunct.gunctweb.managerImpl.proManagerImpl">
    <property name="proDao" ref="proDao" />
    </bean> <bean id="pro" class="com.gunct.gunctweb.action.ProjectAction">
    <property name="proMgr">
    <ref bean="proMgr" />
    </property>
    </bean>

    <!-- news -->
    <bean id="newsDao" class="com.gunct.gunctweb.daoImpl.NewsDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate" />
    </bean> <bean id="newsMgr" class="com.gunct.gunctweb.managerImpl.NewsManagerImpl">
    <property name="newsDao" ref="newsDao" />
    </bean> <bean id="news" class="com.gunct.gunctweb.action.NewsAction">
    <property name="newsMgr">
    <ref bean="newsMgr" />
    </property>
    </bean>
    <!-- message -->

    <bean id="messageDao" class="com.gunct.gunctweb.daoImpl.MessageDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate" />
    </bean>

    <bean id="messageMgr" class="com.gunct.gunctweb.managerImpl.MessageManagerImpl">
    <property name="messageDao" ref="messageDao" />
    </bean>

    <bean id="message" class="com.gunct.gunctweb.action.MessageAction">
    <property name="messageMgr">
    <ref bean="messageMgr" />
    </property>
    </bean>

    <!-- investor -->

    <bean id="investorDao" class="com.gunct.gunctweb.daoImpl.InvestorDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate" />
    </bean>

    <bean id="investorMgr" class="com.gunct.gunctweb.managerImpl.InvestorManagerImpl">
    <property name="investorDao" ref="investorDao" />
    </bean>

    <bean id="investor" class="com.gunct.gunctweb.action.InvestorAction">
    <property name="investorMgr">
    <ref bean="investorMgr" />
    </property>
    </bean>

    <bean id="adminDao" class="com.gunct.gunctweb.daoImpl.AdminDaoImpl">
    <property name="hibernateTemplate" ref="hibernateTemplate"></property>
    </bean>

    <bean id="admin" class="com.gunct.gunctweb.action.AdminAction">
    <property name="adminDao" ref="adminDao"></property>
    </bean>
    </beans>