1.インポートジャーパッケージ
A)MySQLデータベースドライバジャー(MyBatisの-3.2.2)
B)ジャー(MyBatisの-3.2.2)MyBatisの
C)ばねコアジャーパッケージ
私。春豆-4.2.2.RELEASE
II。春・コンテキスト4.2.2.RELEASE
III。春・コア - 4.2.2.RELEASE
IV。春-表現-4.2.2.RELEASE
対コモンズ・ロギング1.1.3
D)スプリングアノテーション(スプリングAOP-4.2.2.RELEASE)
e)は、データベースのトランザクション処理を動作させると、
私。春-側面-4.2.2.RELEASE
II。春-JDBC-4.2.2.RELEASE
III。春-TX-4.2.2.RELEASE
IV。com.springsource.org.aopalliance-1.0.0
V。com.springsource.org.aspectj.weaver-1.6.8.RELEASE
F)データソースジャー(c3p0-0.9.1.1)
グラム)springmvcジャーパッケージ
私。春-ウェブ4.2.2.RELEASE
II。春-webmvc-4.2.2.RELEASE
ジャー(MyBatisのばね-1.3.0)と一体化H)のバネMyBatisの
2.プロファイル
a)は、スプリングの設定ファイル
<?xml version = "1.0" エンコード= "UTF-8"?> <豆のxmlns = "http://www.springframework.org/schema/beans" xmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance" xmlns:コンテキスト= "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-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">
<コンテキスト:コンポーネント・スキャンベースパッケージ=「com.zhiyou100.kfs」> </コンテキスト:コンポーネント・スキャン> <! - (接続オブジェクトの数内部に格納されている)ソース構成データ:データベースとの対話。データソース:C3P0、ドルイド(アリ) - > <ビーンID = "データソース" クラス= "com.mchange.v2.c3p0.ComboPooledDataSource"> <プロパティ名=「ユーザー」値=「ルート」/> <プロパティ名= "パスワード" 値= "123" /> <プロパティ名= "driverClass" 値= "はcom.mysql.jdbc.Driver"> </ property>の <プロパティ名= "jdbcUrlと" 値= "はjdbc:mysqlの://127.0.0.1:3306 /テスト"> </ property>の </豆>
<!-- 配置springJdbc的模板类 --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" autowire="byType"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 定义一个事务管理类 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 开启注解:如果你的事务管理bean的id是transactionManager,属性transaction-manager可以不写 --> <tx:annotation-driven transaction-manager="transactionManager"/> </beans> |
b) springMVC的配置文件
<?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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd 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-4.2.xsd">
<!-- 包扫描 --> <context:component-scan base-package="com.zhiyou100.kfs.controller"></context:component-scan> <!-- 开启注解 --> <mvc:annotation-driven></mvc:annotation-driven> <!-- 静态资源释放 --> <mvc:default-servlet-handler/> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans> |
c) 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" 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>SpringSSM</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> <!-- 编码过滤器 --> <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> <!-- 加载springMVC的配置文件 --> <!-- The front controller of this Spring Web application, responsible for handling all application requests --> <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*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
<!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
<!-- 指定spring的配置文件的路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 加载spring的配置文件 --> <listener> <!-- 默认加载/WEB-INF/applicationContext.xml --> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> |