maven 项目 spring mvc + jdbc 配置文件



<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/task   
    	http://www.springframework.org/schema/task/spring-task-3.0.xsd">
	
	<!-- 启用注解 -->
	<context:annotation-config />
	<!-- 注解扫描的包路径 -->
	<context:component-scan base-package="com.power" />
	<!-- jsp訪问路径 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/page/" />
		<property name="suffix" value=".jsp"/>
	</bean>
	
	<!-- 企业mvc注解 -->
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

	<!-- 加入配置文件 到spring上下文 -->
	<context:property-placeholder location="classpath*:dataSourceConfig.properties" />

	<!-- ************** DataSource: dbcp 数据库配置**************** -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close" lazy-init="false">
		<property name="driverClassName" value="${dbcp.driverClassName}" />
		<property name="url" value="${dbcp.url}" />
		<property name="connectionProperties" value="${dbcp.connectionProperties}" />
		<property name="username" value="${dbcp.username}" />
		<property name="password" value="${dbcp.password}" />
		<property name="initialSize" value="${dbcp.initialSize}" />
		<property name="maxActive" value="${dbcp.maxActive}" />
		<property name="maxIdle" value="${dbcp.maxIdle}" />
		<property name="minIdle" value="${dbcp.minIdle}" />
		<property name="maxWait" value="${dbcp.maxWait}" />
		<property name="logAbandoned" value="${dbcp.logAbandoned}" />
		<property name="removeAbandonedTimeout" value="${dbcp.removeAbandonedTimeout}" />
		<property name="removeAbandoned" value="${dbcp.removeAbandoned}" />
		<property name="poolPreparedStatements" value="${dbcp.poolPreparedStatements}" />
	</bean>


	<!-- *********事物管理************** -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 事物拦截的包路径 -->
	<aop:config>
		<aop:advisor pointcut="execution(* com.power.dao.*.*(..))" 
			advice-ref="txAdvice" />
	</aop:config>
	<!-- 事物拦截的类型 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="select*" read-only="true" />
			<tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
		</tx:attributes>
	</tx:advice>
	<!-- 创建spring jdbcTemplate-->
	<bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	<!-- 定时任务 --> 
	 <task:scheduled-tasks>															
		<task:scheduled ref="taskTrigger" method="showTime" cron="0 1/1 * * * ?" />
	</task:scheduled-tasks> 
	
</beans>
pom文件 spring jdbc + mvc须要的包
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>

  <name>power.plugins</name>
  <groupId>com.framework</groupId>
  <artifactId>power.plugins</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.7</version>
        <configuration>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8888</port>
              <maxIdleTime>30000</maxIdleTime>
            </connector>
          </connectors>
          <webAppSourceDirectory>${project.build.directory}/${pom.artifactId}-${pom.version}</webAppSourceDirectory>
          <contextPath>/</contextPath>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
     
	
    <dependency>
    	<groupId>commons-io</groupId>
    	<artifactId>commons-io</artifactId>
    	<version>${commons-version}</version>
    </dependency>

    <dependency>
    	<groupId>commons-lang</groupId>
    	<artifactId>commons-lang</artifactId>
    	<version>${commons-version}</version>
    </dependency>
    
    
	 <dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>1.2.17</version>
	</dependency>
	 
	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>1.3.1</version>
	</dependency>
	
	
	<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-lang3</artifactId>
	<version>3.3</version>
</dependency>
	
	<dependency>
	<groupId>commons-dbcp</groupId>
	<artifactId>commons-dbcp</artifactId>
	<version>1.4</version>
</dependency>
	
	
	
	<!-- SPRING JDBC -->
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-jdbc</artifactId>
		<version>${spring-version}</version>
	</dependency>
	
	<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-webmvc</artifactId>
	<version>${spring-version}</version>
</dependency>
	
	
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-tx</artifactId>
		<version>${spring-version}</version>
	</dependency>
	
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context</artifactId>
		<version>${spring-version}</version>
	</dependency>
	
	
	<dependency>
		<groupId>javax.transaction</groupId>
		<artifactId>transaction-api</artifactId>
		<version>1.1</version>
	</dependency>
	
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.34</version>
	</dependency>
	
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjweaver</artifactId>
		<version>1.8.4</version>
	</dependency>
	
	<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>4.11</version>
	
	
</dependency>


<dependency>
	<groupId>org.quartz-scheduler</groupId>
	<artifactId>quartz</artifactId>
	<version>2.2.1</version>
</dependency>


  	<dependency>
  		<groupId>org.apache.lucene</groupId>
  		<artifactId>lucene-core</artifactId>
  		<version>4.10.2</version>
  	</dependency>
  </dependencies>
  
  <properties>
  	<spring-version>4.1.2.RELEASE</spring-version>
  	<commons-version>2.2</commons-version>
  </properties>
  
  <url>/</url>
</project>


posted @ 2017-05-18 19:00  lytwajue  阅读(397)  评论(0编辑  收藏  举报