springmvc+mybatis+pgsql+jetbrick整合
2016-07-13 09:34
483 查看
web服务器用的是tomcat,项目用maven管理,数据库连接池用的是阿里巴巴的,日志用的是slf4j和log4j。。。。web.xml
数据库配置文件db.properties
spring的配置文件
springmvc的配置文件
<?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"> <display-name>Archetype Created Web Application</display-name> <!-- spring配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mybatis.xml</param-value> </context-param> <!-- springmvc配置 --> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>jetbrick-template-config-location</param-name> <param-value>classpath:jetbrick-template.properties</param-value> </context-param> <!-- log4j配置--> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <!-- 字符过滤 --> <filter> <filter-name>encodingFilter</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>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
数据库配置文件db.properties
##JDBC Global Setting ##mysql ##jdbc.driver=com.mysql.jdbc.Driver ##jdbc.url=jdbc:mysql://localhost:3306/... ##jdbc.username= ##jdbc.password= #pgql jdbc.driver=org.postgresql.Driver jdbc.url=jdbc:postgresql://localhost:5432/mydb jdbc.username=fd1 jdbc.password=777777 ##DataSource Global Setting ds.initialSize=1 ds.minIdle=1 ds.maxActive=20 ds.maxWait=60000 ds.timeBetweenEvictionRunsMillis=60000 ds.minEvictableIdleTimeMillis=300000
spring的配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" 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:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <context:component-scan base-package="net.smgui"/> <context:property-placeholder location="classpath:db.properties"/> <!-- 数据源 阿里巴巴 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 url、user、password --> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="${ds.initialSize}"/> <property name="minIdle" value="${ds.minIdle}"/> <property name="maxActive" value="${ds.maxActive}"/> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="${ds.maxWait}"/> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}"/> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}"/> <property name="validationQuery" value="SELECT 'x'"/> <property name="testWhileIdle" value="true"/> <property name="testOnBorrow" value="false"/> <property name="testOnReturn" value="false"/> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <!-- <property name="poolPreparedStatements" value="false"/> <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/> 配置监控统计拦截的filters <property name="filters" value="stat"/> --> </bean> <!-- mybatis配置 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> <!-- 事务配置--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.smgui.mapper" /> </bean> </beans>
springmvc的配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="net.smgui"/> <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean id="viewResolver" class="jetbrick.template.web.springmvc.JetTemplateViewResolver"> <property name="order" value="1" /> <property name="contentType" value="text/html; charset=utf-8" /> <property name="suffix" value=".jetx" /> <!-- 指定配置文件 --> <property name="configLocation" value="classpath:jetbrick-template.properties" /> <!-- 直接配置属性 --> <!-- 此处会覆盖configLocation的属性 --> <property name="configProperties"> <props> <prop key="jetx.input.encoding">utf-8</prop> <prop key="jetx.output.encoding">utf-8</prop> </props> </property> </bean> </beans>
相关文章推荐
- 字典序生成排列
- 【转载】Myeclipse 8.6 SVN插件的安装和使用上篇
- 第08章:java常用类库
- Spring.NET学习笔记12——面向切面编程(基础篇) Level 300
- Eclipse和Android Studio2.0检测不到手机的解决方法
- SSH学习之Struts2(一)
- eclipse 快速补全快捷键Ctrl+1修改为AS的Alt+Enter
- 第07章:java开发常用工具介绍
- 001-SpringMVC入门--HelloWorld
- JavaActivity工作流
- 搭建ADT开发环境
- 安卓编译错误:openjdk-8安装
- 第二章:Java语言的基础语法
- Think in Java学习总结(一)之对象
- Spring定时器--时间设置规则
- Java 九九乘法表
- cxf 方式三 是java客户端调用.net服务端 好使代码
- 详解Java多线程编程中CountDownLatch阻塞线程的方法
- 第一章:java概述与开发环境搭建
- Java线程生命周期及其使用,sleep与interrupt的使用,wait与notify