SSH+DB2搭建开发环境(上)

6 篇文章 0 订阅
4 篇文章 0 订阅

1.创建工程之后,倒入基本jar包和log4j.properties

(因网站对附件大小的限制,现将所需jar包分两部分上传。位置分别为http://zhizizhishou0104.iteye.com/blog/1993956http://zhizizhishou0104.iteye.com/blog/1993988 )

2.配置struts

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>
	<constant name="struts.i18n.encoding" value="UTF-8"/>
	<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
	<constant name="struts.configuration.xml.reload" value="true"/>
	<constant name="struts.devMode" value="true"/>
	<constant name="struts.i18n.reload" value="true"/>
	<constant name="struts.convention.classes.reload" value="true" />
	
	<package name="base-package" extends="struts-default">
		<interceptors>
			<interceptor name="loginInterceptor" class="com.abc.web.LoginInterceptor"/>
			<interceptor-stack name="myStack">
				<interceptor-ref name="loginInterceptor"/>
				<!-- 默认拦截器栈
				<interceptor-ref name="defaultStack"/>
				 -->
				<interceptor-ref name="basicStack"/> 
			</interceptor-stack>
		</interceptors>
		<default-interceptor-ref name="myStack"/>
		<global-results>
			<result name="login" type="redirect">/index.jsp</result>
		</global-results>
	</package>
</struts>

 3.配置spring

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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" 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/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
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

	<aop:aspectj-autoproxy />
	<context:component-scan base-package="com.abc.*" />
	
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location" value="classpath:JDBC.properties" />
	</bean>
	
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="${JDBC.DriverName}"/>
		<property name="url" value="${JDBC.URL}"/>
		<property name="username" value="${JDBC.User}"/>
		<property name="password" value="${JDBC.Password}"/>
	</bean>
	
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
		<property name="dataSource" ref="dataSource"/>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${ORM.Dialect}</prop>
				<prop key="hibernate.show_sql">${ORM.ShowSQL}</prop>
				<prop key="hibernate.hbm2ddl.auto">${ORM.HBM2DLL}</prop>
			</props>
		</property>
		<property name="packagesToScan">
			<list>
				<value>com/abc/domain</value>
			</list>
		</property>
	</bean>	
	
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>		
	
	<aop:config>
		<aop:pointcut expression="execution(* com.abc.service.*.*(..))" id="allServiceMethod"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod"/>
	</aop:config>
	
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
			<tx:method name="update*" propagation="REQUIRED"  rollback-for="java.lang.Exception"/>
			<tx:method name="delete*" propagation="REQUIRED"  rollback-for="java.lang.Exception"/>
			<tx:method name="*" propagation="REQUIRED" read-only="true"/>
		</tx:attributes>
	</tx:advice>	
</beans>

4.JDBC.properties

JDBC.DriverName=com.ibm.db2.jcc.DB2Driver
JDBC.URL=jdbc:db2://192.168.1.100:50000/ABC:traceLevel=3;driverType=4;currentSchema=AAA;
JDBC.User=user
JDBC.Password=password

ORM.Dialect=org.hibernate.dialect.DB2Dialect
ORM.ShowSQL=true
ORM.HBM2DLL=update

 5.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>ssh_demo</display-name>

	<filter>
		<filter-name>OpenSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>OpenSessionInViewFilter</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值