根据上篇文章搭建好开发环境后,就可以着手搭建SSM框架的开发架构了
1、打开eclipse
2、新建动态web项目
3、在项目的WebContent目录下的WEB-INF目录下的lib目录下复制所需的jar包,以下是jar包下载地址:
4、在WEB-INF目录下新建web.xml文件,复制以下代码:
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">
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
encoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encoding
*.action
crm
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc-config.xml
1
crm
*.action
index.html
5、在WebContent目录下新建index.html,用于测试
6、在Java Resources目录下新建源文件夹,注意是源文件夹!!!重命名为config
7、在config源文件夹下新建以下配置文件
applicationContext.xml(注意com.itheima.dao和com.itheima.service为你自定义的包)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
class="org.apache.commons.dbcp2.BasicDataSource">
"org.springframework.jdbc.datasource.DataSourceTransactionManager">
class="org.mybatis.spring.SqlSessionFactoryBean">
db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
jdbc.username=root
jdbc.password=123456
jdbc.maxTotal=30
jdbc.maxIdle=10
jdbc.initialSize=5
log4j.properties
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.itheima=DEBUG
# 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
mybatis-config.xml
/p>
"http://mybatis.org/dtd/mybatis-3-config.dtd">
springmvc-config.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="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-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
"org.springframework.web.servlet.view.InternalResourceViewResolver">
8、点击eclipse工具栏上方的Window-Preferences,在弹出的框中找到Server,点击Server下的Runtime Environments,然后点击Add,添加你想要的tomcat服务器,找到本地安装的tomcat服务器,添加完成后在控制台找到Servers,点击下方的蓝色链接将刚刚添加的服务器配置好,将项目添加进服务器。
9、右键点击项目选择在服务器上启动,启动后成功弹出index.html页面,则配置成功,如果报错请自行百度。