最近閒來沒事 最近封裝了一下SSH框架 的一些配置 但具體原來還在理解當中 包括橫切面 點切 事物管理的配置
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/test"/> <property name="user" value="root"/> <property name="password" value="123456"/> <property name="minPoolSize" value="10"/> <!--連接池中保留的最大連接數。Default: 15 --> <property name="maxPoolSize" value="100"/> <!--最大空閒時間,1800秒內未使用則連接被丟棄。若爲0則永不丟棄。Default: 0 --> <property name="maxIdleTime" value="60"/> <!--當連接池中的連接耗盡的時候c3p0一次同時獲取的連接數。Default: 3 --> <property name="acquireIncrement" value="3"/> <property name="maxStatements" value="1000"/> <property name="initialPoolSize" value="10"/> <!--每60秒檢查所有連接池中的空閒連接。Default: 0 --> <property name="idleConnectionTestPeriod" value="30"/> <!--定義在從數據庫獲取新連接失敗後重復嘗試的次數。Default: 30 --> <property name="acquireRetryAttempts" value="30"/> <property name="breakAfterAcquireFailure" value="true"/> <property name="testConnectionOnCheckout" value="false"/> </bean>
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 配置事務管理器 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事務通知 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="select*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="query*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 配置aop --> <aop:config proxy-target-class="true"> <aop:pointcut expression="execution(* com.demo.Service..*(..))" id="pointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/> </aop:config> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="annotatedClasses"> <list> <value>com.demo.Entity.Detai</value> <value>com.demo.Entity.Student</value> <value>com.demo.Entity.Users</value> </list> </property>
這裏會有問題 下面有註釋 <property name="hibernateProperties"> <props> <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <!--添加此句報異常: 在spring的類LocalSessionFactoryBean源碼, 方法buildSessionFactory中將hibernate.current_session_context_class設爲org.springframework.orm.hibernate5.SpringSessionContext <prop key="hibernate.current_session_context_class">thread</prop> --> <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop> </props> </property> </bean>
hibernate4.0 有很多不支持。。封裝的時候會出現各種classnotfound的問題
具體是添加一個 aspectjweaver.jar 的包 纔將錯誤改掉
寫得超級簡單 demo就不上傳了。主要記錄一下是怎麼配置成功的。