旧金山跨海大桥:用maven构建Hibernate+Spring+Struts的web工程
用maven构建Hibernate+Spring+Struts的web工程
转自http://www.diybl.com/course/3_program/java/javajs/2008513/115765.html
写这个还是怕以后忘了。作个备案。供学习和改进:
命令行创建webapp项目:
mvn archetype:create -DgroupId=com.actioner.ssh2 -DartifactId=ssh2 -DarchetypeArtifactId=maven-archetype-webapp
会创建一个叫ssh2的maven web工程。
手动补足test及其下的java resources filters等及main下的java目录
mvn -Declipse.workspace=d:\projects eclipse:add-maven-repo
mvn eclipse:eclipse
在eclipse中配置配置好tomcat,并将ssh2.xml文件放到tocmat的conf\catalian\localhost下.ssh2.xml内容如下:
在eclipse中导入ssh2工程
启动tomcat.在ie中输入url:http://localhost:8080/ssh2
如果出现“Hello World”
则OK!!
继续:
在pom.xml中增加对hibernate3.25.ga spring2.06 struts2.09-core包的依赖。可借助eclipse插件实现
在web.xml中增加struts2框架,并在src\main\resources中增加struts.xml 可以将appfuse项目中的copy过来做为模板
在 web.xml中增加spring框架,并在src\main\resources中增加 ApplicationResources.properties ApplicationResources_zh_CN.properties log4j.xml 等资源文件。均可以将appfuse项目中的copy过来做为模板
applicationContext.xml必须放在src\main\webapp\web-inf下
在applicationContext.xml中一定要设置dataSource和sessionFactory否则会报错。mysql数据库和数据库连接池的依赖包也要加载到pom.xml中
Cannot locate the chosen ObjectFactory implementation: spring 要加载struts2-spring.plugs.jar到pom.xml