用maven构建一个最简单的SSI框架

用maven构建一个最基础的Spring,struts,ibatis框架。(demo在附件中)

一、pom依赖配置:

<!-- 版本配置 -->
<properties>
	<struts.version>2.2.1.1</struts.version>
	<struts.d.javassist>3.12.1.GA</struts.d.javassist>
	<spring.version>3.0.5.RELEASE</spring.version>
	<ibatis.version>2.0.8</ibatis.version>
	<junit.version>4.8.2</junit.version>
	<slf4j.version>1.6.1</slf4j.version>
	<logback.version>0.9.29</logback.version>
</properties>

<!-- 依赖包配置 -->
<dependencies>
	<!-- j2ee5依赖包 -->
	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>servlet-api</artifactId>
		<version>2.5</version>
		<scope>provided</scope>
	</dependency>

	<dependency>
		<groupId>javax.servlet.jsp</groupId>
		<artifactId>jsp-api</artifactId>
		<version>2.1</version>
		<scope>provided</scope>
	</dependency>

	<!-- junit测试依赖包 -->
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>${junit.version}</version>
		<scope>test</scope>
	</dependency>

	<!-- struts2 依赖包 -->
	<dependency>
		<groupId>org.apache.struts</groupId>
		<artifactId>struts2-core</artifactId>
		<version>${struts.version}</version>
	</dependency>

	<dependency>
		<groupId>org.apache.struts</groupId>
		<artifactId>struts2-convention-plugin</artifactId>
		<version>${struts.version}</version>
	</dependency>

	<dependency>
		<groupId>org.apache.struts</groupId>
		<artifactId>struts2-spring-plugin</artifactId>
		<version>${struts.version}</version>
	</dependency>

	<dependency>
		<groupId>javassist</groupId>
		<artifactId>javassist</artifactId>
		<version>${struts.d.javassist}</version>
	</dependency>
	
	<!-- spring 依赖包 -->
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aop</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-test</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-tx</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<!-- ibatis依赖包 -->
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-ibatis</artifactId>
		<version>${ibatis.version}</version>
	</dependency>

	<dependency>
		<groupId>org.apache.ibatis</groupId>
		<artifactId>ibatis-sqlmap</artifactId>
		<version>2.3.4.726</version>
	</dependency>
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.14</version>
	</dependency>
	<dependency>
		<groupId>commons-dbcp</groupId>
		<artifactId>commons-dbcp</artifactId>
		<version>1.4</version>
	</dependency>
	
	<!-- slf4j+LOGBack依赖包 -->
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>log4j-over-slf4j</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>jcl-over-slf4j</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<dependency>
		<groupId>ch.qos.logback</groupId>
		<artifactId>logback-core</artifactId>
		<version>${logback.version}</version>
	</dependency>
	<dependency>
		<groupId>ch.qos.logback</groupId>
		<artifactId>logback-classic</artifactId>
		<version>${logback.version}</version>
	</dependency>

</dependencies>


二、web.xml配置,读取spring的配置文件(spring.xml)
......

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:/spring.xml</param-value>
</context-param>

<listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

......



三、配置spring的配置文件spring.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-3.0.xsd
						http://www.springframework.org/schema/aop 
						http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
						http://www.springframework.org/schema/context
						http://www.springframework.org/schema/context/spring-context-3.0.xsd"
	default-lazy-init="false" default-autowire="byName">
	
	<!-- 组件扫描  start-->
	<context:annotation-config/>
	<context:component-scan base-package="com.myapp"/>
	
	<!-- 读取*.properties配置信息 -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:config/jdbc.properties</value>
			</list>
		</property>
	</bean>
	
	<!-- 数据源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="initialSize" value="10" />
        <property name="maxActive" value="40" />
        <property name="maxIdle" value="5" />
        <property name="password" value="${jdbc.password}" />
        <property name="username" value="${jdbc.username}" />
        <property name="url" value="${jdbc.url}" />
    </bean>

	<!-- spring的ibatis 配置 -->
	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation">
			<value>classpath:config/sqlMapConfig.xml</value>
		</property>
		<property name="dataSource" ref="dataSource" />
	</bean>


</beans>



四、配置jdbc.properties配置文件和sqlMapConifg.xml(这个正常的ibatis的映射配置文件)


至此,一个没有事务、缓存等东西的最精简的框架构建完毕。


你可能感兴趣的:(spring,maven,框架,ibatis,struts)