springmvc+velocity開發配置檔案
阿新 • • 發佈:2018-12-25
一:springmvc-servlet.xml(本檔案和web.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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <mvc:annotation-driven /> <!-- 掃描包 --> <context:component-scan base-package="com.scan,com.test,com.code.test" /> <!-- 配置velocity引擎 --> <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/view/" /> <property name="configLocation" value="classpath:velocity.properties" /> </bean> <!-- 配置檢視的顯示 --> <bean id="ViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <!-- <property name="prefix" value="" />檢視檔案的字首,即存放的路徑 --> <property name="suffix" value=".vm" /><!-- 檢視檔案的字尾名 --> <property name="contentType" value="text/html;charset=UTF-8" /> </bean> <!-- 配置切面 --> <aop:aspectj-autoproxy></aop:aspectj-autoproxy> <bean class="com.scan.aop.advice.AllServiceAspect"></bean> <bean class="com.scan.aop.advice.InterfaceAspect"></bean> <bean class="com.scan.aop.advice.CreateCodeAspect"></bean> </beans>
二:applicationContext-bean.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 配置資料來源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 指定連線資料庫的驅動 --> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <!-- 指定連線資料庫的URL --> <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/xx?characterEncoding=UTF-8" /> <!-- 指定連線資料庫的使用者名稱 --> <property name="user" value="root" /> <!-- 指定連線資料庫的密碼 --> <property name="password" value="123456" /> <!-- 指定連線資料庫連線池的最大連線數 --> <property name="maxPoolSize" value="40" /> <!-- 指定連線資料庫連線池的最小連線數 --> <property name="minPoolSize" value="1" /> <!-- 指定連線資料庫連線池的初始化連線數 --> <property name="initialPoolSize" value="1" /> <!-- 指定連線資料庫連線池的連線的最大空閒時間 --> <property name="maxIdleTime" value="20" /> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean> <bean id="appTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven proxy-target-class="false" transaction-manager="appTransactionManager" /> </beans>
三:velocity.properties
#encoding
input.encoding=UTF-8
output.encoding=UTF-8
#autoreload when vm changed
file.resource.loader.cache=false
file.resource.loader.modificationCheckInterval=2
velocimacro.library.autoreload=false
四:log4j配置
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 %m %n log4j.appender.logfile.MaxFileSize=1024KB log4j.appender.f = org.apache.log4j.FileAppender log4j.appender.f.File = code.log log4j.appender.f.layout = org.apache.log4j.PatternLayout log4j.appender.f.layout.ConversionPattern = %d %m %n log4j.rootLogger =info,stdout,f
五:web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>CharacterEncodingFilter</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-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>