applicationContext.xml配置
ZK+spring+hibernate+log4j的web.xml配置:
<context-param><param-name>webAppRootKey</param-name><param-value>root</param-value></context-param><!--Log4jConfigListener要在ContextLoaderListener前 --><listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><listener><description>Used to clean up when a session is destroyed</description><display-name>ZK Session Cleaner</display-name><listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class></listener><filter><filter-name>loginFilter</filter-name><filter-class>com.mypro.LoginFilter</filter-class></filter><filter-mapping><filter-name>loginFilter</filter-name><url-pattern>*.zul</url-pattern></filter-mapping><servlet><description>ZK loader for ZUML pages</description><servlet-name>zkLoader</servlet-name><servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class><init-param><param-name>update-uri</param-name><param-value>/zkau</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>zkLoader</servlet-name><url-pattern>*.zul</url-pattern></servlet-mapping><servlet><description>The asynchronous update engine for ZK</description><servlet-name>auEngine</servlet-name><servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class></servlet><servlet-mapping><servlet-name>auEngine</servlet-name><url-pattern>/zkau/*</url-pattern></servlet-mapping><error-page><exception-type>java.lang.Throwable</exception-type><location>/error.zul</location></error-page><error-page><error-code>404</error-code><location>/404.zul</location></error-page><!-- MIME mapping --> ……
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 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"><!--IoC自动扫描带@Controller、@Service、@Repository、@Resource、@Transactional等注释的类--><context:component-scan base-package="com.pro.control,com.pro.service.impl,com.pro.dao.hibernate.impl" /><!--配置属性文件的存放地址--> <context:property-placeholder location="WEB-INF/config.properties"/> <bean id="dataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/><property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <bean id="sessionFactory" destroy-method="close"><property name="dataSource" ref="dataSource" /><property name="hibernateProperties"> <props><prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop><prop key="hibernate.current_session_context_class">thread</prop><prop key="hibernate.hbm2ddl.auto">none</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> <prop key="hibernate.c3p0.validate">true</prop><prop key="hibernate.c3p0.max_size">20</prop> <prop key="hibernate.c3p0.min_size">5</prop><prop key="hibernate.c3p0.timeout">120</prop> <prop key="hibernate.c3p0.max_statements">100</prop> <prop key="hibernate.c3p0.idle_test_period">120</prop> <prop key="hibernate.c3p0.acquire_increment">2</prop> <prop key="connection.useUnicode">true</prop> <prop key="connection.characterEncoding">UTF-8</prop> </props></property><!--自动扫描hibernate实体:带@Entity注释--><property name="packagesToScan" value="com.pro.dao.hibernate.vo" /></bean><!-- 事务配置 --><bean id="transactionManager" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager"/><!-- 配置cxf服务器的访问地址:http://192.168.1.120:8000/ --><bean id="endpoint" factory-method="create" /><bean id="clientFactory" value="com.pro.CxfInterface" /><property name="address" value="http://192.168.1.120:8000/" /></bean></beans>
@Controller("employmentCtrl")@Scope("prototype")public class EmploymentCtrl{@Resourceprivate EmploymentService employService;......}
@Service("employService")public class EmploymentServiceImpl implements EmploymentService {@Resourceprivate EmploymentDao employDao;@Override@Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class, timeout = 30)public void addOrEditEmployment{......}
@Entity@Table(name = "employment")public class Employment implements Serializable {private static final long serialVersionUID = 6678401113364404864L;@Id@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "emp_seq")@SequenceGenerator(name = "emp_seq", sequenceName = "seq_emp", allocationSize = 1)private long id; ......
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="CONSOLE" value="[%p] %d [%c.%M()] - %m%n"/> </layout> </appender> <appender name="FILE" value="${root}logs/log.log" /> <param name="Threshold" value="DEBUG" /> <param name="Append" value="true" /> <param name="DatePattern" value="'.'yyyy-MM-dd'.log'" /> <layout value="[%p] %d [%c.%M] - %m%n"/> </layout> </appender> <logger name="org.apache"> <level value="WARN"/> </logger> <logger name="org.springframework"> <level value="WARN"></level> </logger> <logger name="java.sql"> <level value="INFO"/> </logger> <logger name="com.mypro"> <level value="DEBUG"/> </logger> <root> <level value="WARN"/> <appender-ref ref="CONSOLE"/> <appender-ref ref="FILE"/> </root></log4j:configuration>
符号 描述 ------------------------------------------- %d 当前时间 %r 自程序开始后消耗的毫秒数 %t 表示日志记录请求生成的线程 %p 表示日志语句的优先级 %r 与日志请求相关的类别名称 %c 日志信息所在的类名 %M 日志信息所在类的方法 %L 日志信息所在方法的行数 %m%n 表示日志信息的内容