SSH2框架整合并使用JPA注解配置

   最近使用了SSH2框架的JPA注解,

   并以此开发了一个小小的模块 首先将配置文件粘贴如下:

1.web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">

 <display-name>ReaderSys</display-name>
 <welcome-file-list>
  <welcome-file>main.jsp</welcome-file>
 </welcome-file-list>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <filter>
  <filter-name>lazyLoadingFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  <init-param>
   <param-name> flushMode </param-name> 
     <param-value>AUTO </param-value> 
    </init-param>
 </filter>
 
 <!-- Struts2 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> 
 
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>lazyLoadingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- Struts2 filter mapping -->
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>

 

注意标注红色字体的部分,如果不添加此设置,则启动tomcat运行的时候就会报 readonly 问题,即在进行数据库的插入、删除、修改操作时系统会提示readonly 加上此配置后 就可以解决此问题,具体原因在此不再详说。

2.applicationContext.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"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 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
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
           >
          
 <context:annotation-config />
 <context:component-scan base-package="com.Dingxb.ReaderSys" />
 
 <!-- 配置数据源dataSource -->
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
     <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
  <property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=readersys"/>
  <property name="username" value="sa" />
  <property name="password" value="1" />
 </bean>
 <!-- 配置sessionFactory -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
     <property name="dataSource" ref="dataSource"/>
  <property name="hibernateProperties">
   <props>
       <!-- 配置数据库方言 -->
    <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
    <!-- 是否打印SQL语句 -->
    <prop key="hibernate.show_sql">true</prop>
    <!-- 是否让hibernate自动更新数据库 -->
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <!-- 配置c3p0数据源 -->
    <prop key="hibernate.c3p0.max_size">100</prop>
    <prop key="hibernate.c3p0.min_size">5</prop>
    <prop key="hibernate.c3p0.acquire_increment">5</prop>
    <prop key="hibernate.c3p0.max_statements">200</prop>
    <prop key="hibernate.c3p0.idle_test_period">3000</prop>
    <prop key="hibernate.c3p0.timeout">5000</prop>
   </props>
  </property>
  <property name="packagesToScan">
   <list>
    <value>com.Dingxb.ReaderSys.Model</value> 
   </list>
  </property>
 </bean>
 <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
 <!--配置事务管理器 -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
 <!--配置事务特性,配置add、update和delete开始的方法,事务传播特性为required -->
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="add*" propagation="REQUIRED" />
   <tx:method name="update*" propagation="REQUIRED" />
   <tx:method name="delete*" propagation="REQUIRED" />
   <tx:method name="*" read-only="true" />
  </tx:attributes>
 </tx:advice>
 <aop:config>
  <aop:pointcut id="allManagerMethod" expression="execution(* com.Dingxb.ReaderSys.Service.*.*(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
 </aop:config>
</beans>

3.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.0.dtd">

<struts>

    <package name="ReaderSys" namespace="/" extends="struts-default">
   
  <action name="*Readerdict" class="com.Dingxb.ReaderSys.Action.ReaderdictAction" method="{1}Readerdict">
     <result name="listReaderdictSucc">/readerdict.jsp</result>
      <result name="addReaderdictSucc">/readerdict.jsp</result>
       <result name="deleteReaderdictSucc">/readerdict.jsp</result>
       <result name="updatebuttonReaderdictSucc">/readerdictupdate.jsp</result>
        <result name="updateReaderdictSucc">/readerdict.jsp</result>
     <result name="listReaderdictFail">/maintest.jsp</result>
  </action>
 </package>
</struts>
4.struts.properties

 

struts.devMode = true
struts.configuration.xml.reload = true
struts.action.extension = action
struts.enable.DynamicMethodInvocation = true
struts.multipart.saveDir = /tmp

 

5.log4j.properties

 

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=warn, stdout
log4j.logger.com.opensymphony.xwork2=ERROR

#log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug

### log cache activity ###
#log4j.logger.org.hibernate.cache=debug

### log transaction activity
#log4j.logger.org.hibernate.transaction=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace

以上是SSH2的配置文件

 

具体的配置文件在附件中,有需要的可以查看一下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值