谁能给个范例?用spring的注解和hbm文件用jpa代替,并使用声明事务
org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator我配置的老是跑不起来求高手帮忙给个范例
以下是我的applicationContext和web.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" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://www.springframework.org/schema/context 
 http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="com.tinyblog" />
    
<!-- configure dataSource -->
<!--
use jdbc DataSource <bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"> <value>com.mysql.jdbc.Driver</value>
</property> <property name="url">
<value>jdbc:mysql://localhost:3306/tinyblog?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=GBK</value>
</property> <property name="username"> <value>root</value> </property>
<property name="password"> <value>root</value> </property> </bean>
-->
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="alias">
<value>spring</value>
</property>
<property name="driver">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="driverUrl">
<value>jdbc:mysql://localhost:3306/tinyblog?useUnicode=true&amp;characterEncoding=GBK</value>
   </property>
   <property name="user">
    <value>root</value>
   </property>
   <property name="password">
    <value>root</value>
   </property>
</bean>
  <!-- configure dataSource -->
  
  <!-- Hibernate 3 configure--> 
  
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
destroy-method="close">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>

<property name="annotatedClasses">
               <list>
                   <value>com.tinyblog.domain.User</value>                   
               </list>
           </property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> 
                    org.hibernate.dialect.MySQLDialect 
                </prop>
<prop key="hibernate.show_sql">
                    false
                   </prop>
</props>
</property>
</bean>
       
      <!-- Hibernate 3 configure-->
      
      
    <!--   定义事务管理器,使用适用于Hibernte的事务管理器-->
<bean id="transactionManager"
         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <!--   HibernateTransactionManager   bean需要依赖注入一个SessionFactory bean的引用-->
            <property name="sessionFactory">
             <ref local="sessionFactory"/>
            </property>
</bean>
     <!--   配置事务拦截器-->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <!--   事务拦截器bean需要依赖注入一个事务管理器 -->
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transactionAttributes">
            <!--   下面定义事务传播属性-->
            <props>
                <prop key="insert*">PROPAGATION_REQUIRED</prop>
                <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
</bean>
     <!--   定义事务Advisor-->
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
        <!--   定义advisor时,必须传入Interceptor-->
            <property name="transactionInterceptor" ref="transactionInterceptor"/>
        </bean>
     <!-- DefaultAdvisorAutoProxyCreator搜索容器中的 advisor,并为每个bean创建代理 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
<!--定义DAO Bean ,由于BeanNameAutoProxyCreator自动生成事务代理-->
     

</beans>
web.xml<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">
<display-name>tinyblog</display-name>

<!-- load Spring configure files -->  
    <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>/WEB-INF/applicationContext.xml</param-value>  
    </context-param> 

<!-- character encoding filter -->  
    <filter>  
        <filter-name>encodingFilter</filter-name>  
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
        <init-param>  
            <param-name>encoding</param-name>  
            <param-value>UTF-8</param-value>  
        </init-param>  
    </filter>   
    <!-- character encoding filter --> 

<!-- configure Struts2's filter --> 
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!-- configure Struts2's filter --> 
<!-- mapping struts2's filter -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- mapping struts2's filter -->

<!-- load Spring's applicationContext -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- load Spring's applicationContext -->

<!-- Spring refresh Introspectoprevent to prevent memory leak -->
<listener>  
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
    </listener>  
    <!-- Spring refresh Introspectoprevent to prevent memory leak -->
    
    <!-- session timeout setting  5 minite  --> 
    <session-config>  
        <session-timeout>5</session-timeout>  
    </session-config>  
     <!-- session timeout setting  5 minite  --> 

<!-- log4j configure -->
<context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>WEB-INF/classes/log4j.properties</param-value>
    </context-param>
    <context-param>
        <param-name>log4jRefreshInterval</param-name>
        <param-value>10000</param-value>
    </context-param>
<listener>
        <listener-class>
            org.springframework.web.util.Log4jConfigListener
        </listener-class>
    </listener>
<!-- log4j configure -->

    <!-- default welcome files (startup) -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
    <!-- default welcome files (startup) -->
</web-app>

解决方案 »

  1.   

    下面是我的工程中的配置文件,给你参考下。——applicationContext和web的
    application配置文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd"><beans>
    <bean id="jdbcConfigurer" class="org.ejs.util.JdbcConfigurer">
    <property name="location">
    <value>jdbc.properties</value>
    </property>
    <property name="decrypt">
    <value>false</value>
    </property>
    </bean> <!-- Hibernate Datasource -->
    <bean id="oracleDS" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName">
    <value>${jdbc.driver}</value>
    </property>
    <property name="url">
    <value>${jdbc.url}</value>
    </property>
    <property name="username">
    <value>${jdbc.user}</value>
    </property>
    <property name="password">
    <value>${jdbc.password}</value>
    </property>
    <property name="validationQuery">
    <value>${jdbc.validationquery}</value>
    </property>
    <property name="testOnBorrow">
    <value>${jdbc.testonborrow}</value>
    </property>
    <property name="maxActive">
    <value>${jdbc.maxactive}</value>
    </property>
    <property name="maxIdle">
    <value>${jdbc.maxidle}</value>
    </property>
    </bean> <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="oracleDS"></property>
    <property name="mappingDirectoryLocations">
    <list>
    <value>classpath:/org/ejs/hr/model</value>
    <value>classpath:/org/ejs/sys/model</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <!-- 数据库相关配置 -->
    <prop key="hibernate.dialect">
    org.hibernate.dialect.Oracle9Dialect
    </prop> <prop key="hibernate.connection.provider_class">
    org.hibernate.connection.DatasourceConnectionProvider
    </prop> <prop key="hibernate.query.substitutions">
    true 1, false 0
    </prop>
    <!-- Create/update the database tables automatically when the JVM starts up -->
    <!--
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    --> <!-- 一次读的数据库记录数 -->
    <prop key="hibernate.jdbc.fetch_size">100</prop>
    <!-- 设定对数据库进行批量删除 -->
    <prop key="hibernate.jdbc.batch_size">50</prop>
    <!-- executeBatch()返回正确的行计数 -->
    <prop key="hibernate.jdbc.batch_versioned_data">
    true
    </prop> <!-- 将Hibernate发送给数据库的sql显示出来 -->
    <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.release_mode">
    after_transaction
    </prop>
    <!-- 为单向关联(一对一, 多对一)的外连接抓取(outer join fetch)树最大深度 -->
    <prop key="hibernate.max_fetch_depth">1</prop>
    <prop key="hibernate.cache.use_minimal_puts">true</prop> <!-- 是否使用查询缓存 -->
    <prop key="hibernate.cache.use_query_cache">false</prop> <!-- 设置Hibernate的缓存接口类,这个类在Hibernate包中 -->
    <prop key="hibernate.cache.provider_class">
    org.hibernate.cache.EhCacheProvider
    </prop>
    </props>
    </property>
    </bean> <bean id="hibernateContext"
    class="org.ejs.context.HibernateContext">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <bean id="hibernateInterceptor"
    class="org.springframework.orm.hibernate3.HibernateInterceptor">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    <property name="cacheQueries">
    <value>true</value>
    </property>
    </bean> <bean id="jdbcTemplate"
    class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
    <ref bean="oracleDS" />
    </property>
    </bean> <bean id="jdbcDaoSupport"
    class="org.ejs.dao.support.JdbcDaoSupport">
    <property name="jdbcTemplate">
    <ref bean="jdbcTemplate" />
    </property>
    </bean> <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
    <props>
    <prop key="store">PROPAGATION_REQUIRED</prop>
    <prop key="create">PROPAGATION_REQUIRED</prop>
    <prop key="update">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="submit">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_SUPPORTS,readOnly</prop>
    <prop key="get*">PROPAGATION_SUPPORTS,readOnly</prop>
    <prop key="executeUpdate">PROPAGATION_REQUIRED</prop>
    <prop key="executeQuery">
    PROPAGATION_SUPPORTS,readOnly
    </prop>
    <prop key="pagedQuery">
    PROPAGATION_SUPPORTS,readOnly
    </prop>
    </props>
    </property>
    </bean>
    </beans>
      

  2.   


    WEB配置文件:
    <?xml version="1.0"?>
    <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>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
    <param-name>facelets.REFRESH_PERIOD</param-name>
    <param-value>2</param-value>
    </context-param>
    <context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
    </context-param>
    <context-param>
    <param-name>com.sun.faces.validateXml</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>com.sun.faces.verifyObjects</param-name>
    <param-value>false</param-value>
    </context-param>
    <context-param>
    <param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
    <param-value>true</param-value>
    </context-param>
    <context-param>
    <param-name>org.ajax4jsf.COMPRESS_STYLE</param-name>
    <param-value>false</param-value>
    </context-param>
    <context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>classic</param-value>
    </context-param>
    <context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>DEFAULT</param-value>
    </context-param>
    <context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>DEFAULT</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>
    /WEB-INF/faces-config.xml, /WEB-INF/faces-config-hr.xml,
    /WEB-INF/faces-config-crm.xml, /WEB-INF/faces-config-ddm.xml
    </param-value>
    </context-param>
    <filter>
    <display-name>Ajax4jsf Filter</display-name>
    <filter-name>ajax4jsf</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>ajax4jsf</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <listener>
    <listener-class>
    com.sun.faces.config.ConfigureListener
    </listener-class>
    </listener>
    <listener>
    <listener-class>
    org.ejs.context.ContextLoaderListener
    </listener-class>
    </listener>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <login-config>
    <auth-method>BASIC</auth-method>
    </login-config>
    </web-app>
      

  3.   

    帮忙顶一下,代码太多了,而且没放在JAVA code里,看不来
      

  4.   

    ftp://www.v512.com/video/spring/s2s2h3_01.avi
    用迅雷把这个STRUTS2_SPRING2+HIBERNATE3整合下来看看,就知道他们直接相机作用的原理
    也就会明白如何配置了