最近无聊,就想着做一下ssm的整合~在网上先去找资料,但是发现大多都不是入门级。尤其是需要哪些jar,都没有注明出来。 那么我就写一篇,算作是入门的教程,高手勿拍砖~ 一、准备工作 首先去找struts的. http://struts./ 下载最新的struts 2.3.7. (在发这篇文章前我发现已经升级到了2.3.8) 然后再去找spring的. http://www./spring-framework 下载spring-framework-3.2.0.RELEASE-dist 最后自然就是MyBatis3.0的 http://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DMyBatis 下载MyBatis的-3.1.1-bundle 二、提取需要用到的jar 这里呢,我就直接做ssm的整合。 不分解做。所以不理解的童鞋可以先照我的做。 下去后可以自己度娘,谷哥去找分解整合。 struts需要的jar: spring 所需的jar: MyBatis所需的jar 其他所需jar
struts2-core-2.3.7.jar spring-aop.jar
mybatis-3.1.1.jar commons-dbcp-1.4.jar struts2-spring-plugin-2.3.7.jar OK,我们已经提取出了整合所需的基本jar。 本人用的是oracle数据库,所以引入了classes12.jar。可以根据自己的需求换。 我们先把这些jar放到我们项目的lib下。这个我想大家都会。
到现在为止我们把所需要的jar全部导入进去了。 但是还没有关联。那么现在我们开始做关联配置。 applicationContext.xml
jdbc.properties 1 db.driver=oracle.jdbc.driver.OracleDriver 2 db.url=jdbc:oracle:thin:@localhost:1521:orcl 3 db.username= 4 db.password= 5 db.alias=OraclePool 6 db.minIdle=5 7 db.maxIdle=10 8 db.maxWait=5 9 db.maxActive=20 10 db.initialSize=10 11 db.logWriter= 12 db.validationQuery=SELECT 1 FROM DUAL mybatis.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-////DTD Config 3.0//EN" "http:///dtd/mybatis-3-config.dtd"> <configuration> <!-- 别名 --> <typeAliases> </typeAliases> </configuration> struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts./dtds/struts-2.0.dtd"> <struts> <package name="my-default" abstract="true" extends="struts-default"> </package> </struts> 到此为止,我们已经把框架整合到了一起。 部署到tomcat运行。 2012-12-29 11:38:13 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_25\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;F:\oracle\product\11.1.0\db_1\bin;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\Java\jdk1.6.0_25\bin;C:\Program Files\Java\jdk1.6.0_25\jre\bin;F:\Program Files\apache-maven-3.0.4\bin;f:\program files\eclipse; 2012-12-29 11:38:13 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ssm' did not find a matching property. 2012-12-29 11:38:13 org.apache.coyote.http11.Http11Protocol init 信息: Initializing Coyote HTTP/1.1 on http-8080 2012-12-29 11:38:13 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 482 ms 2012-12-29 11:38:13 org.apache.catalina.core.StandardService start 信息: Starting service Catalina 2012-12-29 11:38:13 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engine: Apache Tomcat/6.0.32 2012-12-29 11:38:14 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 2012-12-29 11:38:14,936 [org.apache.ibatis.logging.LogFactory]-[DEBUG] Logging initialized using 'org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl' adapter. 2012-12-29 11:38:14,949 [org.mybatis.spring.SqlSessionFactoryBean]-[DEBUG] Property 'configLocation' not specified, using default MyBatis Configuration 2012-12-29 11:38:16,155 [org.mybatis.spring.SqlSessionFactoryBean]-[DEBUG] Property 'mapperLocations' was not specified or no matching resources found 2012-12-29 11:38:17 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-8080 2012-12-29 11:38:17 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8009 2012-12-29 11:38:17 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/22 config=null 2012-12-29 11:38:17 org.apache.catalina.startup.Catalina start 信息: Server startup in 3410 ms 有错误信息~~ 请不要紧张。是因为我们并没有把mybatis完全整合进来。 配置文件里注释掉了引用。这些等项目架构规划好都可以放开使用。 本人也是初次做ssm的整合。 谨以此文献给那些想学习ssm 整合的童鞋们。 |
|