1. 程式人生 > >SSM整合開發xml配置檔案內容springmvc-config/application/web

SSM整合開發xml配置檔案內容springmvc-config/application/web

SSM(spring-springmvc-mybatis)整合開發xml配置檔案內容springmvc-config.xml,application.xml,web.xml

這是我寫的一個人事管理系統其中的一部分

寫此博文為了將其分享出來,一方面為了儲存下來,以後開發專案的時候,直接複製一些套路的程式碼.

博友可以互相關注,互相學習.

1.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"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	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-4.3.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
	<!-- 將此包下面的類作為spring的bean注入 -->
	<mybatis-spring:scan base-package="dreamyy.top.hrm.dao"/>
	<!-- 載入資料來源引數 -->
	<context:property-override location="classpath:db.properties"/>
	<!-- 配置c3p0資料來源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"></bean>
	<!-- 配置mybatis用於整合Spring的bean -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource"></bean>
	<!-- jdbc事務管理器 -->
	<bean id = "transactionManager" 
			class="org.springframework.jdbc.datasource.DataSourceTransactionManager" 
			p:dataSource-ref="dataSource">
	</bean>
	<!-- 啟用支援annotation註解方式的事務管理 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
	<!-- 部署業務邏輯元件  新增spring註解的類 -->
	<context:component-scan base-package="dreamyy.top.hrm"></context:component-scan>
</beans>

2.springmvc的配置檔案springmvc-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: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-4.3.xsd
		    			http://www.springframework.org/schema/mvc 
		    			http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
	<context:component-scan base-package="dreamyy.top.hrm.controller"></context:component-scan>
	<!-- 設定預設配置檔案 -->
	<mvc:annotation-driven/>
	<!-- 使用預設的servlet來響應靜態檔案 -->
	<mvc:default-servlet-handler/>
	<!-- 定義springmvc攔截器 -->
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/*"/>
			<bean class="dreamyy.top.hrm.interceptor.AuthorizedInterceptor"></bean>
		</mvc:interceptor>
	</mvc:interceptors>
	<!--檢視解析器 -->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<!-- 字首 -->
		<property name="prefix">
			<value>/WEB-INF/jsp/</value>
		</property>
		<!-- 字尾 -->
		<property name="suffix">
			<value>.jsp</value>
		</property>
	</bean>
	<!-- 配置檔案上傳下載 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 檔案上傳大小上限  大小為位元組(10M) -->
		<property name="maxUploadSize">
			<value>10485760</value>
		</property>
		<property name="defaultEncoding">
			<value>UTF-8</value>
		</property>
	</bean>
</beans>


3.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" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>hrmapp</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>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/springmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <jsp-config>
    <jsp-property-group>
      <url-pattern>*.jsp</url-pattern>
      <el-ignored>false</el-ignored>
      <scripting-invalid>true</scripting-invalid>
      <include-prelude>/WEB-INF/jsp/taglib.jsp</include-prelude>
    </jsp-property-group>
  </jsp-config>
  <error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
  </error-page>
</web-app>