ssm 框架配置详解
生活随笔
收集整理的這篇文章主要介紹了
ssm 框架配置详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
環境信息
JDK1.7 + Tomcat7 + spring4.0
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_4_0.xsd"version="4.0"><welcome-file-list><welcome-file>index.html</welcome-file></welcome-file-list><!-- post請求編碼設置 --><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><!--監聽器: 監聽項目啟動,加載配置文件--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- spring 掃描--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:conf/spring-application.xml</param-value></context-param><!-- spring mvc --><servlet><servlet-name>springMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:conf/spring-mvc.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> </web-app>spring-application.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.1.xsd"><context:property-placeholder location="classpath:conf/application.properties"/><!-- 數據源配置 --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="{jdbc.driver}"/><property name="url" value="{jdbc.url}"/><property name="username" value="{jdbc.username}"/><property name="password" value="{jdbc.password}"/></bean><!-- 數據工廠配置 --><bean id="sqlFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="configLocation" value="classpath:conf/mybatis-config.xml"/><property name="typeAliasesPackage" value="com.huawei.demo.entity"/><!-- 掃描mapper.xml文件 --><property name="mapperLocations"><list><value>classpath:mapper/*.xml</value></list></property></bean><!-- 掃描da層接口--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.huawei.demo.mapper"/><property name="sqlSessionFactoryBeanName" value="sqlFactory"/></bean><!-- 掃描出控制層之外的service層 --><context:component-scan base-package="com.huawei.demo"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><bean id="txManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!-- 啟用事務注解驅動,自動掃描注冊 --><tx:annotation-driven transaction-manager="txManage"/><import resource="classpath:conf/spring-mvc.xml"/></beans>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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 只掃描控制層 --><context:component-scan base-package="com.huawei.demo"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 靜態資源處理 --><mvc:default-servlet-handler/><!-- 視圖解析 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/page/"/><property name="suffix" value=".html"/></bean><!-- 靜態資源加載 --><mvc:resources location="/static/" mapping="/static/**"/><!-- 攔截器 --><mvc:interceptors><mvc:interceptor><mvc:mapping path="/**" /><bean class="com.huawei.demo.interceptor.LoginInterceptor"/></mvc:interceptor></mvc:interceptors><mvc:annotation-driven /></beans>mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><settings><!-- 使用數據庫自增主鍵 --><setting name="useGeneratedKeys" value="true"/><!-- 使用列別名--><setting name="useColumnLabel" value="true"/><!-- 啟用駝峰命名轉換--><setting name="mapUnderscoreToCamelCase" value="true"/></settings> </configuration>項目結構
依賴jar包
總結
以上是生活随笔為你收集整理的ssm 框架配置详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nested exception is
- 下一篇: fatal: No configured