- 下载各种jar包
mybatis下载
https://github.com/mybatis/mybatis-3/releases
mysql驱动下载
http://mvnrepository.com/artifact/mysql/mysql-connector-java
spring下载(spring所用到的所有jar包,包括springmvc)
http://repo.spring.io/release/org/springframework/spring/
配合spring使用的工具类收录(开发包大全),最终版本3.0.2,后面就不更新了。
需要用到的jar:
- aopalliance jar包 AOP联盟的API包,里面包含了针对面向切面的接口。 通常Spring等其它具备动态织入功能的框架依赖此包
- aspectjweaver-1.6.11.jar aspectjweaver是spring的切入点表达式需要用的包
链接:https://pan.baidu.com/s/1rCt4z5JV9BW-MZlsOg1cRg 密码:m222
mybatis-spring jar包下载
http://mvnrepository.com/artifact/org.mybatis/mybatis-spring/1.3.2
第三方数据库连接池druid
http://mvnrepository.com/artifact/com.alibaba/druid
Json依赖包Jackson
junit
http://mvnrepository.com/artifact/junit/junit/4.9
-
各种文件配置
jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/crm?characterEncoding=utf-8 jdbc.username=root jdbc.password=root
log4j.properties
# Global logging configuration log4j.rootLogger=DEBUG, stdout # 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
applicationContext.xml
- 配置 读取properties文件 jdbc.properties
- 通过注解,将Service的生命周期纳入Spring的管理
- 配置数据源
- 注解事务
- 开启注解
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <context:property-placeholder location="classpath:jdbc.properties"/> <!--通过注解,将Service的生命周期纳入Spring的管理--> <context:annotation-config /> <context:component-scan base-package="com.ssm.service" /> <!--配置数据源--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <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="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="typeAliasesPackage" value="com.ssm.pojo" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.ssm.dao"/> </bean> <!-- 注解事务 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 开启注解 --> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
springmvc.xml
- 配置Controller扫描
- 配置注解驱动
- 视图解释器
-
静态页面,如html,css,js,images可以访问
<?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-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!--扫描controller ,service --> <context:component-scan base-package="dx"/> <!--静态页面,如html,css,js,images可以访问--> <mvc:default-servlet-handler /> <!--注解驱动,以使得访问路径与方法的匹配可以通过注解配置--> <mvc:annotation-driven /> <!-- 视图解释器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </be