ssm框架及基本配置

整个项目目录:

基本jar包全图:

applicationContext.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: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/context
   http://www.springframework.org/schema/context/spring-context.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">
    
     <!-- 导入配置 -->    
     <import resource="springdao-config.xml"/>
     <import resource="springdb-config.xml"/>
    
    <import resource="springtx-config.xml"/>
 
</beans>
 

----------------------------------------------------------------------------------------------------------------------------------------

springdao-config.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:p="http://www.springframework.org/schema/p"
    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">
                        
     <!-- 自动扫描dao的接口文件,并注入IOC容器 -->
     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
         <property name="basePackage" value="com.fu.dao"></property>
     </bean>            
</beans>

------------------------------------------------------------------------------------------------------------------------

springdb-config.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:p="http://www.springframework.org/schema/p"
    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">
    <!-- 读取db.properties文件 -->
    <context:property-placeholder location="classpath:db.properties" />
    
    <!-- 配置数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="minIdle" value="${jdbc.minIdle}"></property>
        <property name="maxActive" value="${jdbc.maxActive}"></property>
        <property name="maxWait" value="${jdbc.maxWait}"></property>
        <property name="initialSize" value="${jdbc.initialSize}"></property>
    </bean>
    
    
    <!-- 配置Mybatis工厂 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 制定核心配置文件 -->
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <!-- 制定数据源 -->
        <property name="dataSource" ref="dataSource"></property>
        
        <property name="mapperLocations" value="classpath:com/fu/mapper/*.xml"></property> 
    </bean>
                        
</beans>

 

-----------------------------------------------------------------------------------------------------------------------

springtx-config.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: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/context
   http://www.springframework.org/schema/context/spring-context.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="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    
    <context:component-scan base-package="com.fu.service"/>
    
    <!-- 开启事务注解扫描 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    
    <!--  注解方式
    <tx:advice id="allTx" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*" rollback-for="java.lang.Exception" propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>
    
    <aop:config>
    <aop:pointcut expression="execution(* com.fu.service..*.*(..))" id="txp"/>
        <aop:advisor advice-ref="allTx" pointcut-ref="txp"/>
    </aop:config>
-->
</beans>

 

-----------------------------------------------------------------------------------------------------------------------

spriingmvc-config.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:mvc="http://www.springframework.org/schema/mvc"
    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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        
        <!--避免IE执行AJAX时,返回JSON出现下载文件
        <bean id="mappingJacksonHttpMessageConverter"
            class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <value>text/html;charset=UTF-8</value>
                </list>
            </property>
        </bean> -->
        
        <!-- 配置包扫描器 -->
        <context:component-scan base-package="com.fu.controller" />
        
        <!-- 配置注解驱动 -->
        <mvc:annotation-driven />
        <!-- restful
        <mvc:default-servlet-handler/> -->
        
        <!-- 完成请求和注解POJO的映射  JSON转换器 
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                <list>
                    <ref bean="mappingJacksonHttpMessageConverter" />    
                </list>
            </property>
        </bean>-->
        
        <!-- 配置拦截器 
        <mvc:interceptors>
            <mvc:interceptor>
                <mvc:mapping path="/**"/>
                
                <mvc:exclude-mapping path="/**/*.css"/>            
                <mvc:exclude-mapping path="/**/*.js"/>            
                <mvc:exclude-mapping path="/**/*.html"/>
                <mvc:exclude-mapping path="/**/*.jpg"/>
                <mvc:exclude-mapping path="/**/*.png"/>
                <mvc:exclude-mapping path="/**/*.gif"/>
                
                <bean class="com.sw.interceptor.LoginInterceptor"></bean>
            </mvc:interceptor>
        </mvc:interceptors>-->
        
        <!-- 配置视图解析器 -->
        <bean id="ViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"></property>
            <property name="suffix" value=".jsp"></property>
            </bean>
    
        <!-- 配置上传文件解析编码格式 -->
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="defaultEncoding" value="UTF-8"></property>
            <!-- 文件大小最大值 -->
            <property name="maxUploadSize" value="10485760000" />  
            <!-- 内存中的最大值 -->
            <property name="maxInMemorySize" value="40960" />  
        </bean>
            
</beans>

-------------------------------------------------------------------------------------------------------------------------

mybatis-config.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "mybatis-3-config.dtd" >
<configuration>
    <!-- 指定别名  该包下的实体类都是首字母小写 -->
    <typeAliases>
        <package name="com.fu.pojo"/>
    </typeAliases>
</configuration>


------------------------------------------------------------------------------------------------------------------

db.properties配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "mybatis-3-config.dtd" >
<configuration>
    <!-- 指定别名  该包下的实体类都是首字母小写 -->
    <typeAliases>
        <package name="com.fu.pojo"/>
    </typeAliases>
</configuration>


-----------------------------------------------------------------------------------------------------------------------------------------

log4j.properties配置:

# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.fu=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

------------------------------------------------------------------------------------------------------------------------------------

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值