ssm:简单整合开发框架

来源:互联网 发布:安捷伦数据采集器软件 编辑:程序博客网 时间:2024/06/07 11:07

写在项目开始:

致自己:要抬头看天,也要注意低头看路,不要走得太快,忘记了为什么出发。

开发框架搭建:

maven下构建:

spring+springmvc+mybatis+TKmybatis+redis+shiro+activiti+logback......

pom.xml

<properties><scope>compile</scope><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><spring.version>4.3.0.RELEASE</spring.version><spring.data.version>1.7.2.RELEASE</spring.data.version><mybatis.version>3.3.1</mybatis.version><mybatis.spring.version>1.2.2</mybatis.spring.version><mapper.version>3.3.8</mapper.version><pagehelper.version>4.1.6</pagehelper.version><c3p0.version>0.9.5.2</c3p0.version><shiro.version>1.2.4</shiro.version><logback.version>1.1.3</logback.version></properties><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.8</source><target>1.8</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins></build><dependencyManagement><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-framework-bom</artifactId><version>${spring.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>provided</scope><version>4.12</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><scope>${scope}</scope><version>3.1.0</version></dependency><dependency><groupId>javax.transaction</groupId><artifactId>jta</artifactId><version>1.1</version></dependency><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version><scope>${scope}</scope></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.1</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>${logback.version}</version><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><scope>${scope}</scope><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><scope>${scope}</scope></dependency><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId><version>${spring.data.version}</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.35</version><scope>${scope}</scope></dependency><dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>${c3p0.version}</version><scope>${scope}</scope></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.5.3</version><scope>${scope}</scope></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.5.3</version><scope>${scope}</scope></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-annotations</artifactId><version>2.5.3</version><scope>${scope}</scope></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.7</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>${mybatis.version}</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>${mybatis.spring.version}</version></dependency><dependency><groupId>tk.mybatis</groupId><artifactId>mapper</artifactId><version>${mapper.version}</version></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>${pagehelper.version}</version></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-core</artifactId><version>${shiro.version}</version><scope>${scope}</scope></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-web</artifactId><version>${shiro.version}</version><scope>${scope}</scope></dependency><dependency><groupId>org.apache.shiro</groupId><artifactId>shiro-spring</artifactId><version>${shiro.version}</version><scope>${scope}</scope></dependency><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.8.0</version><scope>${scope}</scope></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-engine</artifactId><version>5.20.0</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-spring</artifactId><version>5.20.0</version></dependency></dependencies>

其余依赖包根据实际情况调整。

信息配置文件:config.properties

#sql dialectsql.dialect=mysql#thread sizeexecutor.size=30scheduler.size=30#pool propertiesinitialSize=0minIdle=10maxActive=300#default data sourcedb.driverClassName=com.mysql.jdbc.Driverdb.url=jdbc:mysql://localhost:3306/ssmdb.username=rootdb.password=root#####################################################jedis pool properties####################################################jedis.maxTotal=300jedis.maxIdle=300jedis.minIdle=1#redis host redis.host=localhostredis.port=6379#select redis db from 0 to 16,redis total 16 db defaultredis.db=0#####################################################


spring配置文件:application-context.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:task="http://www.springframework.org/schema/task" xmlns:cache="http://www.springframework.org/schema/cache"xmlns:c="http://www.springframework.org/schema/c" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context.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.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"><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/config.properties</value></list></property></bean><context:component-scan base-package="com.xxx"><context:exclude-filter type="annotation"expression="org.springframework.stereotype.Controller" /></context:component-scan><aop:config proxy-target-class="true" /><task:annotation-driven executor="executor"scheduler="scheduler" /><task:executor id="executor" pool-size="${executor.size}" /><task:scheduler id="scheduler" pool-size="${scheduler.size}" /><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="configLocation" value="classpath:spring/mybatis-configuration.xml" /><property name="mapperLocations" value="classpath*:**/mapper/${sql.dialect}/**/*.xml" /></bean><bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.bda.**.mapper" /><!-- 禁用顶层接口后所有mapper均可扫描 --><!-- <property name="markerInterface" value="tk.mybatis.mapper.common.Mapper"/> --><property name="properties"><value>ORDER=BEFORE</value></property></bean><import resource="datasource-context.xml" /></beans>

数据库连接配置:datasource-context.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:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:c="http://www.springframework.org/schema/c"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context.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="user" value="${db.username}" /><property name="password" value="${db.password}" /><property name="driverClass" value="${db.driverClassName}" /><property name="jdbcUrl" value="${db.url}" /><property name="maxPoolSize" value="10" /><property name="minPoolSize" value="1" /><property name="initialPoolSize" value="4" /><property name="maxIdleTime" value="60" /></bean><bean id="txManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><tx:annotation-driven transaction-manager="txManager" /><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><!-- all methods starting with 'get' are read-only --><tx:method name="get*" read-only="true" /><tx:method name="select*" read-only="true" /><tx:method name="count*" read-only="true" /><tx:method name="search*" read-only="true" /><tx:method name="list*" read-only="true" /><tx:method name="find*" read-only="true" /><!-- other methods use the default transaction settings (see below) --><tx:method name="*" /></tx:attributes></tx:advice></beans>

mybatis配置:mybatis-configuration.xml


<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration></configuration>

springmvc配置:servlet-context.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:beans="http://www.springframework.org/schema/beans"xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scan base-package="com.bda"use-default-filters="false"><context:include-filter type="annotation"expression="org.springframework.stereotype.Controller" /></context:component-scan><mvc:annotation-driven enable-matrix-variables="true"><mvc:message-converters><beans:beanclass="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value></list></property></beans:bean></mvc:message-converters></mvc:annotation-driven><mvc:default-servlet-handler /><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/" /><property name="suffix" value=".jsp" /></bean></beans>

web.xml配置


<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"metadata-complete="true" version="3.1"><context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:spring/application-context.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><async-supported>true</async-supported><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><servlet-mapping><servlet-name>default</servlet-name><url-pattern>/assets/*</url-pattern></servlet-mapping><servlet><servlet-name>dispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath*:spring/servlet-context.xml</param-value></init-param><load-on-startup>1</load-on-startup><async-supported>true</async-supported><multipart-config><max-file-size>52428800</max-file-size><max-request-size>52428800</max-request-size><file-size-threshold>0</file-size-threshold></multipart-config></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>index.html</welcome-file></welcome-file-list><error-page><exception-type>java.lang.NullPointerException</exception-type><location>/error/null</location></error-page><error-page><exception-type>java.lang.Exception</exception-type><location>/error/exception</location></error-page></web-app>

日志配置:开发日志

<?xml version="1.0" encoding="UTF-8"?><configuration><property name="pattern"value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n" /><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><encoder><pattern>${pattern}</pattern></encoder></appender><logger name="com.bda.xxx" level="debug" /><root level="error"><appender-ref ref="STDOUT" /></root></configuration>

eclipse下tomcat习惯设置:
1 设置Timeouts 
个人习惯:300s
2 path:/
3 Auto reloading:Disabled

最后:让项目先跑起来!再根据进展逐步完善。
原创粉丝点击