项目导入
登录http://www.springframework.org/download官方网站下载 spring-framework-2.5.4-with-dependencies.zip,解压缩
在Eclipse中选择:新建Web项目,然后将jpetstore目录中的SRC下的源码复制到我们刚刚新建的工程中;然后将war目录的文件复制到WebRoot目录,将所需的JAR包复制到lib目录,同时修改jdbc.property文件,如下:
Java代码
# Properties file with JDBC-related settings.
# Applied by PropertyPlaceholderConfigurer from "dataAccessContext-local.xml".
# Targeted at system administrators, to avoid touching the context XML files.
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/test
jdbc.username=root
jdbc.password=******
# Properties file with JDBC-related settings.
# Applied by PropertyPlaceholderConfigurer from "dataAccessContext-local.xml".
# Targeted at system administrators, to avoid touching the context XML files.
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/test
jdbc.username=root
jdbc.password=******
只需要修改成自己的数据库配置即可
安装
Ø 在build.xml所在目录的上层目录建立lib目录,拷贝Spring lib目录下的所有jar文件,并且拷贝Spring.jar到lib目录(默认lib目录下没有spring.jar)
Ø 在lib同层目录建立dist目录
Ø ant warfile
Ø 将生成的jpetstore.war文件拷贝到tomcat webapps目录下
Ø 将spring.jar拷贝到WEB-IN/lib目录下,否则tomcat初始化Spring监听器org.springframework.web.context.ContextLoaderListener会找不到类。
Ø 修改jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost/jpetstore
jdbc.username=root
jdbc.password=
Ø 修改web.xml,使用struts
<servlet-mapping>
<!--
<servlet-name>petstore</servlet-name>
-->
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
● web.xml配置
ØSpring 配置1
<!-- 指定根application context的xml配置文件的位置,被ContextLoaderServlet 或 -ContextLoaderListener使用,可以指定多个文件。 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dataAccessContext-local.xml /WEB-INF/applicationContext.xml
</param-value>
</context-param>
ØSpring配置2
<!--
- 在web app启动的时候,加载根application context
- 默认会从"/WEB-INF/applicationContext.xml"读取配置信息
- 如果是Servlet 2.4以上的容器,最好使用ContextLoaderListener 监听起启动
-AppFuse提供了一个如何使用ContextLoaderListener初始化Spring的实例。
- 在应用中使用 -WebApplicationContextUtils.getWebApplicationContext(servletContext)控制
-application context-->
<!—通过监听器加载Application Context,旧版本的JpetStore使用ContextLoaderServlet 加载-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Østruts配置1
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
Østruts配置2
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
ØdataAccessContext-local.xml中配置数据源
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url"><value>${jdbc.url}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
Ø 数据源信息会自动从配置文件相同目录下的jdbc.properties中读取
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://localhost:9002
jdbc.username=sa
jdbc.password=
分享到:
相关推荐
学习iBatis,快速入门, 源代码包括宠物商店
spring自带的JPetStore,我已经配置好(数据库也配置好,用的是hsqldb),可以直接导 入eclipse中运行。共3个压缩包
spring自带的JPetStore,我已经配置好(数据库也配置好,用的是hsqldb),可以直接导入eclipse中运行。共3个压缩包
jpetstore-3-1-1
spring自带的JPetStore,我已经配置好(数据库也配置好,用的是hsqldb),可以直接导 入eclipse中运行。共3个压缩包
JPet商店样品 该示例说明了如何将与集成。 此外,该示例对于结合以下库很有用: Spring安全胸腺Hibernate验证器您需要Java 11或更高版本才能构建和运行此示例。克隆git clone ...
mybatis-spring-boot-jpetstore 该示例是一个基于MyBatis,Spring Boot(Spring MVC,Spring Security)和Thymeleaf的Web应用程序。 这是MyBatis JPetStore示例应用程序( )的另一种实现。 原始应用程序可在...
使用了mybatis的jpetstore-6
MyBatis学习范例宠物商店jpetstore6 内容为: mybatis-jpetstore-6.0.0-sources.jar mybatis-jpetstore-6.0.0.war 学习MyBatis一定要看的sample。
配置jpetstore时候,数据库常常发生错误,收集了一些配置时候错误的修改方法
iBATIS_JPetStore-4.0.5
jpetstore-4.0.3
ibaits 示例,供大家分享,哈哈哈哈哈哈哈哈 哈哈啊哈哈和哈哈哈哈和
该jpetstore经典案例为最新SPRING开发包里面的完全案例,并集成到eclipse里面了,在eclipse里面可以直接运行并调试,在工作目录里面直接建立jpetstore目录,自动导入该目录下文件,修改jdbc.properties配置文件,连接...
Jpetstore
jpetstore系统架构图
iBATIS JPetStore
jpetstore-ibatis