SSM开发环境的搭建(方式一)
2016-12-03 00:00
537 查看
SSM全称:Spring-SpringMVC-MyBatis
1.导包。2.配置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" id="WebApp_ID" version="2.5"> <servlet> <servlet-name>springweb</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springweb</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <filter> <filter-name>encoding</filter-name> <filter-class> .......xxxFilter </filter-class> <init-param> <param-name>contentType</param-name> <param-value>text/html;charset=utf8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
3.在src下建立包。
4.进行配置文件。
config.properties是存储mysql信息的。
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/db_note username=root password=root maxActive=10 maxWait=5000
spring-web.xml 扫描加载controller使用的配置。
<?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:util="http://www.springframework.org/schema/util" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 扫描web层的@Controller --> <context:component-scan base-package=""/> <mvc:annotation-driven/> </beans>
spring-web.xml 扫描加载service层使用的配置。
<?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:util="http://www.springframework.org/schema/util" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 扫描service层的@Service --> <context:component-scan base-package=""/> <mvc:annotation-driven/> </beans>
spring-mabatis.xml 扫描加载mybatis进行配置.
<?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:util="http://www.springframework.org/schema/util" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 加载mysql配置文件 --> <util:properties id="dbcp" location="classpath:config.properties"/> <!-- 数据源,可以是dbcp,c3p0,或其他的,以dbcp为例 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="#{dbcp.driverClassName}"/> <property name="url" value="#{dbcp.url}"/> <!-- ?useUnicode=true&characterEncoding=utf8 --> <property name="username" value="#{dbcp.username}"/> <property name="password" value="#{dbcp.password}"/> <property name="maxActive" value="#{dbcp.maxActive}"/> <property name="maxWait" value="#{dbcp.maxWait}"/> </bean> <!-- 创建sqlSession --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!-- 扫描dao包,转换成映射 --> <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value=""/> </bean> <!-- spring-mybatis.xml --> <!-- 创建事务管理器Bean --> <bean id="txMgr" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 事务管理器必须注入 dataSource 对象 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 开启事务注解支持,可以使用注解管理事务--> <!-- 必须注入 事务管理器对象 --> <tx:annotation-driven transaction-manager="txMgr"/> </beans>
spring-aop.xml 扫描加载aop包。
<?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:util="http://www.springframework.org/schema/util" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"> <!-- 扫描aop包 --> <context:component-scan base-package=""/> <!-- 打开AOP注解支持,用于支持@Aspect --> <!-- 加上参数proxy-target-class="true"后会强制使用cglib --> <aop:aspectj-autoproxy proxy-target-class="true"/> </beans>
log4j.properties 配置log4j进行日志信息的打印输出。示例,可不相同。
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.err log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### direct messages to file mylog.log ### log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=c:\mylog.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### log4j.rootLogger=info, stdout
5.测试mybatis连接数据库是否成功。
6.开始开发。
相关文章推荐
- SSM开发环境的搭建(方式二)
- 在Windows平台搭建C语言开发环境的多种方式
- 以InfiniBand为通信方式的MPICH2开发环境的搭建
- Maven搭建SSM(SpringMVC + Spring + Mybaits)开发环境 (下)
- Maven的SSM开发环境的搭建
- 搭建Spark开发环境的几种方式及入门示例
- 离线方式搭建android开发环境
- mybatis实战教程之开发环境搭建、以接口的方式编程、实现数据的增删改查
- Struts2-搭建开发环境使用三种方式输出
- Laravel学习-三种方式搭建开发环境
- HBase、Hive、MapReduce、Hadoop、Spark 开发环境搭建后的一些步骤(export导出jar包方式 或 Ant 方式)
- Golang开发环境搭建(Notepad++、LiteIDE两种方式以及martini框架使用)
- 非在线方式搭建Android开发环境
- 在ubuntu下纯指令方式搭建php开发环境
- windows下Apache + python(mod_python方式)开发环境的搭建
- VS2005下WTL开发环境搭建方式
- windows 下php 开发环境的多种搭建方式
- MyBatis教程之开发环境搭建和以接口的方式编程
- SSM环境搭建(接口编程方式)
- (SSM框架)SpringMVC+Spring4+Mybatis+Maven环境快速搭建开发案例