spring

web 应用 如果spring容器中的Bean需要request,session,globalsession
作用域的支持需注册
org.springframework.web.context.request.RequestContextListener


struct 结合
<constant name="struts.objectFactory" value="spring"/>

<!--可以采用注解方式定义bean @Component、 @Repository、@Service或 @Controller  structs action需注意用 @Scope("prototype")
-->
<context:component-scan base-package="org.example"/>



hibernate 使用

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
    <property name=”connection.autoReconnect”>true</property>
    <property name=”connection.autoReconnectForPools”>true</property>
    <property name=”connection.is-connection-validation-required”>true</property>
</bean>

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="mappingResources">
      <list>
        <value>product.hbm.xml</value>
      </list>
    </property>
    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.HSQLDialect
      </value>
    </property>
</bean>

<!--注入sessionFactory  可以采用注解方式声明自动注入-->
<bean id="myProductDao" class="product.ProductDaoImpl">
    <property name="sessionFactory" ref="mySessionFactory"/>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!--事务通知-->
<tx:advice id="txAdvice">
        <tx:attributes>
            <tx:method name="*"/>
        </tx:attributes>
</tx:advice>

<aop:config>
  <aop:pointcut id="123" expression="execution(* x.y.service.xxxxService.*(..))"/>
  <aop:advisor advice-ref="txAdvice" pointcut-ref="123"/>
</aop:config>


你可能感兴趣的:(spring)