zoukankan      html  css  js  c++  java
  • 单体应用SSM

    properties

    log4j.properties

    log4j.rootLogger=INFO, console, file
    
    log4j.appender.console=org.apache.log4j.ConsoleAppender
    log4j.appender.console.layout=org.apache.log4j.PatternLayout
    log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n
    
    log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.File=logs/log.log
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.A3.MaxFileSize=1024KB
    log4j.appender.A3.MaxBackupIndex=10
    log4j.appender.file.layout.ConversionPattern=%d %p [%c] - %m%n
    

    website.properties

    #============================#
    #==== JDBC settings ====#
    #============================#
    # JDBC
    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.connectionURL=jdbc:mysql://localhost:3306/website?useUnicode=true&characterEncoding=utf-8&useSSL=false
    jdbc.username=root
    jdbc.password=123456
    
    # JDBC Pool
    jdbc.pool.init=1
    jdbc.pool.minIdle=3
    jdbc.pool.maxActive=20
    
    # JDBC Test
    jdbc.testSql=SELECT 'x' FROM DUAL
    
    
    #============================#
    #==== File settings ====#
    #============================#
    
    # 视图文件存放路径
    web.view.prefix=/WEB-INF/views/
    web.view.suffix=.jsp
    
    #文件上传
    web.maxUploadSize=10485760
    
    #API
    api.path.v1=/api/v1
    api.path.v2=/api/v2
    
    #============================#
    #==== Email settings ====#
    #============================#
    email.host.name=smtp.qq.com
    email.smtp.port=465
    email.username=279205343@qq.com
    email.password=tsipqubpwmbjcaga
    
    

    数据库配置

    spring-context-druid.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"
           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">
    
        <!-- 加载配置属性文件 -->
        <context:property-placeholder ignore-unresolvable="true" location="classpath:website.properties"/>
    
        <!-- 数据源配置, 使用 Druid 数据库连接池 -->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
            <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
            <property name="driverClassName" value="${jdbc.driverClass}"/>
    
            <!-- 基本属性 url、user、password -->
            <property name="url" value="${jdbc.connectionURL}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
    
            <!-- 配置初始化大小、最小、最大 -->
            <property name="initialSize" value="${jdbc.pool.init}"/>
            <property name="minIdle" value="${jdbc.pool.minIdle}"/>
            <property name="maxActive" value="${jdbc.pool.maxActive}"/>
    
            <!-- 配置获取连接等待超时的时间 -->
            <property name="maxWait" value="60000"/>
    
            <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
            <property name="timeBetweenEvictionRunsMillis" value="60000"/>
    
            <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
            <property name="minEvictableIdleTimeMillis" value="300000"/>
    
            <property name="validationQuery" value="${jdbc.testSql}"/>
            <property name="testWhileIdle" value="true"/>
            <property name="testOnBorrow" value="false"/>
            <property name="testOnReturn" value="false"/>
    
            <!-- 配置监控统计拦截的filters -->
            <property name="filters" value="stat"/>
        </bean>
    </beans>
    

    mybatis-config.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>
        <!-- 全局参数 -->
        <settings>
            <!-- 打印 SQL 语句 -->
            <setting name="logImpl" value="STDOUT_LOGGING" />
    
            <!-- 使全局的映射器启用或禁用缓存。 -->
            <setting name="cacheEnabled" value="false"/>
    
            <!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 -->
            <setting name="lazyLoadingEnabled" value="true"/>
    
            <!-- 当启用时,有延迟加载属性的对象在被调用时将会完全加载任意属性。否则,每种属性将会按需要加载。 -->
            <setting name="aggressiveLazyLoading" value="true"/>
    
            <!-- 是否允许单条 SQL 返回多个数据集 (取决于驱动的兼容性) default:true -->
            <setting name="multipleResultSetsEnabled" value="true"/>
    
            <!-- 是否可以使用列的别名 (取决于驱动的兼容性) default:true -->
            <setting name="useColumnLabel" value="true"/>
    
            <!-- 允许 JDBC 生成主键。需要驱动器支持。如果设为了 true,这个设置将强制使用被生成的主键,有一些驱动器不兼容不过仍然可以执行。 default:false  -->
            <setting name="useGeneratedKeys" value="false"/>
    
            <!-- 指定 MyBatis 如何自动映射 数据基表的列 NONE:不映射 PARTIAL:部分 FULL:全部  -->
            <setting name="autoMappingBehavior" value="PARTIAL"/>
    
            <!-- 这是默认的执行类型 (SIMPLE: 简单; REUSE: 执行器可能重复使用prepared statements语句;BATCH: 执行器可以重复执行语句和批量更新) -->
            <setting name="defaultExecutorType" value="SIMPLE"/>
    
            <!-- 使用驼峰命名法转换字段。 -->
            <setting name="mapUnderscoreToCamelCase" value="true"/>
    
            <!-- 设置本地缓存范围 session:就会有数据的共享 statement:语句范围 (这样就不会有数据的共享 ) defalut:session -->
            <setting name="localCacheScope" value="SESSION"/>
    
            <!-- 设置 JDBC 类型为空时,某些驱动程序 要指定值, default:OTHER,插入空值时不需要指定类型 -->
            <setting name="jdbcTypeForNull" value="NULL"/>
        </settings>
    </configuration>
    

    spring-context-mybatis.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"
           xsi:schemaLocation="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">
    
        <!-- 配置 SqlSession -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <!-- 用于配置对应实体类所在的包,多个 package 之间可以用 ',' 号分割 -->
            <property name="typeAliasesPackage" value="org.jit.sose.entity"/>
            <!-- 用于配置对象关系映射配置文件所在目录 -->
            <property name="mapperLocations" value="classpath:mapping/**/*.xml"/>
            <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
        </bean>
    
        <!-- 扫描 Mapper -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="org.jit.sose.mapper" />
        </bean>
    </beans>
    

    spring配置

    spring-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"
           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">
    
        <!--开启注解模式-->
        <context:annotation-config />
        <context:component-scan base-package="org.jit.sose">
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
    
        <!-- 配置 Bean Validator 定义,因为validator是静态的,相当于属性,spring只能自动注入对象,这里要自己手动注入 -->
        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
        <bean id="beanValidator" class="org.jit.sose.commons.validator.BeanValidator">
            <property name="validator" ref="validator" />
        </bean>
    
        <!-- 配置事务管理器 -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
        <!-- 开启事务注解驱动 -->
        <tx:annotation-driven transaction-manager="transactionManager" />
    </beans>
    

    spring-context-email.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"
           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">
    
        <!-- 加载配置属性文件 -->
        <context:property-placeholder ignore-unresolvable="true" location="classpath:website.properties"/>
        <bean id="emailSendUtils" class="org.jit.sose.commons.utils.EmailSendUtils"/>
        <bean id="email" class="org.apache.commons.mail.SimpleEmail">
            <property name="hostName" value="${email.host.name}"/>
            <property name="smtpPort" value="${email.smtp.port}"/>
            <property name="authenticator">
                <bean class="org.apache.commons.mail.DefaultAuthenticator">
                    <constructor-arg name="userName" value="${email.username}"/>
                    <constructor-arg name="password" value="${email.password}"/>
                </bean>
            </property>
            <property name="SSLOnConnect" value="true"/>
            <property name="from" value="${email.username}"/>
        </bean>
    
    </beans>
    

    spring-context-kaptcha.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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
            <property name="config">
                <bean class="com.google.code.kaptcha.util.Config">
                    <constructor-arg>
                        <props>
                            <prop key="kaptcha.border">yes</prop>
                            <prop key="kaptcha.border.color">105,179,90</prop>
                            <prop key="kaptcha.textproducer.font.color">blue</prop>
                            <prop key="kaptcha.image.width">125</prop>
                            <prop key="kaptcha.image.height">45</prop>
                            <prop key="kaptcha.textproducer.font.size">45</prop>
                            <prop key="kaptcha.session.key">code</prop>
                            <prop key="kaptcha.textproducer.char.length">4</prop>
                            <prop key="kaptcha.textproducer.font.names">宋体,楷体,微软雅黑</prop>
                        </props>
                    </constructor-arg>
                </bean>
            </property>
        </bean>
    </beans>
    

    MVC

    spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
           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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <description>Spring MVC Configuration</description>
    
        <!-- 加载配置属性文件 -->
        <context:property-placeholder ignore-unresolvable="true" location="classpath:website.properties"/>
    
        <!-- 使用 Annotation 自动注册 Bean,只扫描 @Controller -->
        <context:component-scan base-package="org.jit.sose" use-default-filters="false">
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
    
        <!-- 默认的注解映射的支持 -->
        <mvc:annotation-driven />
    
        <!-- 定义视图文件解析 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="${web.view.prefix}"/>
            <property name="suffix" value="${web.view.suffix}"/>
        </bean>
    
        <!-- 静态资源映射 -->
        <mvc:resources mapping="/static/**" location="/static/" cache-period="31536000"/>
    
    
        <!-- 拦截器配置,拦截顺序:先执行后定义的,排在第一位的最后执行。-->
        <mvc:interceptors>
            <mvc:interceptor>
                <mvc:mapping path="/**"/>
                <mvc:exclude-mapping path="/static/**"/>
                <mvc:exclude-mapping path="/login"/>
                <mvc:exclude-mapping path="/verification"/>
                <bean class="org.jit.sose.webapp.interceptor.LoginInterceptor"/>
            </mvc:interceptor>
            <mvc:interceptor>
                <mvc:mapping path="/**"/>
                <mvc:exclude-mapping path="/static/**"/>
                <mvc:exclude-mapping path="/login"/>
                <bean class="org.jit.sose.webapp.interceptor.PermissionInterceptor"/>
            </mvc:interceptor>
        </mvc:interceptors>
    
        <!-- 上传文件拦截,设置最大上传文件大小 10M = 10*1024*1024(B) = 10485760 bytes -->
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize" value="10485760"/>
        </bean>
    </beans>
    

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1">
    
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-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>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                <param-name>forceEncoding</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>encodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
    
        <servlet>
            <servlet-name>springServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath*:/spring-mvc*.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>springServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
        <!--  <servlet-mapping>
              <servlet-name>default</servlet-name>
              <url-pattern>*.css</url-pattern>
              <url-pattern>*.js</url-pattern>
              <url-pattern>*.html</url-pattern>
              <url-pattern>*.jpg</url-pattern>
              <url-pattern>*.png</url-pattern>
              <url-pattern>*.eot</url-pattern>
              <url-pattern>*.svg</url-pattern>
              <url-pattern>*.ttf</url-pattern>
              <url-pattern>*.woff</url-pattern>
          </servlet-mapping>-->
    
    
        <!-- <servlet>
             <servlet-name>DruidStatView</servlet-name>
             <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
         </servlet>
         <servlet-mapping>
             <servlet-name>DruidStatView</servlet-name>
             <url-pattern>/druid/*</url-pattern>
         </servlet-mapping>-->
    
    </web-app>
    
  • 相关阅读:
    2016第41周二
    2016第41周一
    2016第40周日
    svn冲突
    海量数据搜索
    网页爬虫的设计与实现(Java版)
    Eclipse中使用正则表达式搜索替换
    nodpad++正则替换
    DWR3.0 dwr 返回值(数组,集合,Map)
    自己用反射写的一个request.getParameter工具类
  • 原文地址:https://www.cnblogs.com/faramita/p/Java.html
Copyright © 2011-2022 走看看