ssm配置文件

6 篇文章 0 订阅

spring配置文件 :  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"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- dataSource -->
    <!-- 读取properties文件 -->
    <context:property-placeholder location="classpath:dbinfo.properties"/>
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${driverClassName}"></property>
        <property name="jdbcUrl" value="${jdbc.url}"></property>
        <property name="user" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>

    <!-- sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
    </bean>

    <!-- dao
        扫描mapper层 创建代理对象
     -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
        <property name="basePackage" value="com.it.mapper"></property>
    </bean>

  </beans>

spring事务配置applicationContext-tx.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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/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">


    <!-- service -->
    <!-- 扫描service层所在的包 -->
    <context:component-scan base-package="com.it.service"></context:component-scan>

    <!-- 事务控制
        	1)事务管理器
        	2)事务的详情
        	3)aop配置  把事务织入到service层方法中
         -->

    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 事务的详情 -->
    <tx:advice id="myAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
        </tx:attributes>
    </tx:advice>

    <!-- aop配置 -->
    <aop:config>
        <aop:advisor advice-ref="myAdvice" pointcut="execution(* com.it.service.impl.*.*(..))"/>
    </aop:config>

</beans>

springmvc配置文件springmvc-servlet.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-4.3.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">
     
     <!-- 扫描注解 -->  
     <context:component-scan base-package="com.itqf.controller"></context:component-scan>

  	<mvc:annotation-driven></mvc:annotation-driven>
  	<!-- 映射器 -->
  	<!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>
  	<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  		<property name="messageConverters">
  			<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
  		</property>
  	</bean>-->

	<!--freemarker的配置-->
	<!-- freemarker的配置 -->
	<bean id="freemarkerConfigurer"
		  class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<!-- 前缀  文件的目录 -->
		<property name="templateLoaderPath" value="/WEB-INF/ftl/" />
		<property name="defaultEncoding" value="UTF-8" />
		 <property name="freemarkerSettings">
         <props>
               <prop key="template_update_delay">10</prop>
               <prop key="locale">zh_CN</prop>
               <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
               <prop key="date_format">yyyy-MM-dd</prop>
               <prop key="time_format">HH:mm:ss</prop>
               <prop key="number_format">#.##</prop>
           </props>
        </property>
	</bean>


	<!-- freemaker的视图解析器 -->
	<!-- 配置FreeMark视图 -->
	<bean id="freeMarkerViewResolver"
		  class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="contentType" value="text/html;charset=UTF-8" />
		<!-- 后缀 -->
		<property name="suffix" value=".html" />
		<!--         <property?name="requestContextAttribute"?value="request"?/>
         -->	</bean>
<!-- 正常视图解析器 
    	 
    	 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	 	<property name="suffix" value=".jsp"></property>
    	 	<property name="prefix" value="/WEB-INF/jsp/"></property>
    	 </bean>  --> 
	<mvc:default-servlet-handler/>


</beans>

Mybatis配置文件sqlMapconfig.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>

   <!-- 显示执行的sql语句 -->
   <settings>
        <!-- 打印sql语句 -->
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
    
  	<!-- 插件  分页插件 -->
  
  <plugins>
  	<plugin interceptor="com.github.pagehelper.PageHelper">
  		<property name="dialect" value="mysql"/>
  	</plugin>
  	 <!--5.0版本pagehelper-->
		<!-- <plugin interceptor="com.github.pagehelper.PageInterceptor">
				<property name="helperDialect" value="mysql"/>
		</plugin> -->
  	
  </plugins>
  
</configuration>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>ssm_bookmanager</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <listener>
    <listener-class>com.itqf.web.MyListener</listener-class>
  </listener>

  
  <servlet>
    <servlet-name>springDispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springDispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <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>

dbinfo.properties

driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://47.107.154.7:3306/demo?unicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=Zxc130517.

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值