java整合SSM框架的图文教程

网友投稿 352 2023-03-17


java整合SSM框架的图文教程

使用Myeclipse搭建maven项目

准备工作

安装maven

官网下载安装(http://maven.apache.org/)

配置环境变量

配置完后,使用命令行输入mvn -version查看是否配置成功,出现以下界面表示配置成功。

2. 在MyEclipse中配置maven

打开MyEclipse2015————点击菜单栏Window———选项栏Preference ,搜索Maven,进入Installations,点击Add引入安装的maven。

进入User Setting,设置Global Setting,选中安装的maven的settings.xml配置文件(以上步骤已经完成maven配置)

3. 创建项目(检测是否配置成功,这里创建的是web项目)

点击项目右键->Run as->Maven install将依赖install至本地maven库,有可能会报:

-Dmaven.multiModuleProjectDirectorysystem propery is not set. Check $M2_HOME environment variable and mvn scriptmatch.,

表示JDK版本和maven有冲突,更改一下jdk版本,并且加上-Dmaven.multiModuleProjectDirectory=$M2_HOME即可;

如运行过程中控制台如下图所示,表示成功。

在maven项目中搭建spring+springMVC+MyBatis

修改pom.xml添加对应的包依赖

javax.servlet

javax.servlet-api

3.0.1

compile

jstl

jstl

1.2

c3p0

c3p0

0.9.1

com.alibaba

druid

1.0.25

com.alibaba

jconsole

com.alibaba

tools

org.springframework

spring-core

4.1.7.RELEASE

org.springframework

spring-beans

4.1.7.RELEASE

org.springframework

spring-tx

4.1.7.RELEASE

org.springframework

spring-context

4.1.7.RELEASE

org.springframework

spring-context-support

4.1.7.RELEASE

org.springframework

spring-web

4.1.7.RELEASE

org.springframework

spring-webmvc

4.1.7.RELEASE

org.springframework

spring-aop

4.1.7.RELEASE

org.springframework

spring-aspects

4.1.7.RELEASE

org.springframework

spring-jdbc

4.1.7.RELEASE

org.aspectj

aspectjweaver

1.8.5

junit

junit

4.12

org.mybatis

mybatis

3.4.1

&MzBXPlAlt;dependency>

log4j

log4j

1.2.17

org.mybatis

MzBXPlA mybatis-spring

1.3.0

mysql

mysql-connector-java

5.1.38

com.mchange

mchange-commons-java

0.2.10

commons-codec

commons-codec

1.10

dom4j

dom4j

1.6.1

com.thoughtworks.xstream

xstream

1.3.1

net.sf.json-lib

json-lib

2.4

jdk15

xom

xom

1.2.5

org.apache.httpcomponents

httpclient

4.2.5

com.github.pagehelper

pagehelper

4.0.0

tk.mybatis

mapper

3.3.8

commons-httpclient

commons-httpclient

3.1

org.jdom

jdom

1.1.3

修改web.xml,配置驱动及过滤器和加载Spring配置文件

index.html

index.htm

index.jsp

default.html

default.htm

default.jsp

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:applicationContext*.xml

springDispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml

1

springDispatcherServlet

/

创建并配置applicationContext.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:p="http://springframework.org/schema/p"

xmlns:tx="http://springframework.org/schema/tx" xmlns:context="http://springframework.org/schema/context"

xmlns:aop="http://springframework.org/schema/aop"

xmlns:jaxws="http://cxf.apache.org/jaxws"

xsi:schemaLocation="http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.1.xsd

http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd

http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.1.xsd">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

expression="execution(* cn.ft.service.impl.*Impl.*(..))" />

advice-ref="transactionAdvice" />

xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:p="http://springframework.org/schema/p"

xmlns:tx="http://springframework.org/schema/tx" xmlns:context="http://springframework.org/schema/context"

xmlns:aop="http://springframework.org/schema/aop"

xmlns:jaxws="http://cxf.apache.org/jaxws"

xsi:schemaLocation="http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.1.xsd

http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd

http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.1.xsd">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

expression="execution(* cn.ft.service.impl.*Impl.*(..))" />

advice-ref="transactionAdvice" />

expression="execution(* cn.ft.service.impl.*Impl.*(..))" />

advice-ref="transactionAdvice" />

advice-ref="transactionAdvice" />

创建并配置springmvc.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:context="http://springframework.org/schema/context"

xmlns:aop="http://springframework.org/schema/aop"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.3.xsd

http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-4.3.xsd

http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.1.xsd">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

/refuse

application/json;charset=UTF-8

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:context="http://springframework.org/schema/context"

xmlns:aop="http://springframework.org/schema/aop"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.3.xsd

http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-4.3.xsd

http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-4.1.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.1.xsd">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

/refuse

class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

/refuse

application/json;charset=UTF-8

配置数据源db.properties

driverClassName=com.mysql.jdbc.Driver

validationQuery=SELECT 1

jdbc_url=jdbc\:mysql\://localhost\:3306/ft?useUnicode\=true&characterEncoding\=UTF-8&zeroDateTimeBehavior\=convertToNull

jdbc_username=root

jdbc_password=8888

配置mybatis-config.xm

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

配置log4j.properties

log4j.rootCategory=DEBUG, stdout , R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

log4j.appender.R.File=D\:\\Tomcat 5.5\\logs\\qc.log

log4j.appender.R.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:路由器管理员密码默认(怎么改路由器密码)
下一篇:判断滚动条滑到底部触发事件(实例讲解)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~