spring链接配置即可。
一、<dependencyManagement>
<dependencies>
<!-- 使用spring的BOM管理依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
二、<!-- spring配置开始 --><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- spring配置结束 -->
三、在web工程的src/main/resources/META-INF目录下添加dispatcher.xml文件,并添加如下配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
applicationContext.xml文件里,<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:compass="http://www.compass-project.org/schema/spring-core-config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.compass-project.org/schema/spring-core-config http://www.compass-project.org/schema/spring-compass-core-config-2.1.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/mysql" />
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="user" value="root"></property>
<property name="password" value=""></property>
<property name="maxPoolSize" value="40" />
<property name="minPoolSize" value="1" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20" />
</bean>
搭建struts应用2.1 引入需要的jar包
commons-fileupload-1.2.1.jar 文件上传
commons-logging-1.0.4.jar 日志包
freemarker-2.3.13.jar Sturts2的所有UI标记
ognl-2.6.11.jar OGNL表达式相关
struts2-core-2.1.6.jar Struts2的核心包
xwork-2.1.2.jar XWork2 库。Struts2核心包,做为底层存在
2.2 加入配置文件 struts.xml, struts.properties
2.3 将struts加入到web.xml的配置中,将请求交由struts来处理
2.4 编写Action类,无需继承任何类和实现任何接口
2.5 在struts.xml中加入对action的配置
搭建spring的框架
2.1 加入jar包
SPRING_HOME/dist/spring.jar
SPRING_HOME/lib/log4j/log4j.jar
SPRING_HOME/jakarta-commons/commons-logging.jar
2.2 加入配置文件
SPRING_HOME/samples/jpetstore/war/WEB-INF/log4j.properties
SPRING_HOME/samples/jpetstore/war/WEB-INF/applicationContext.xml
2.3 将写好的类加入到spring的管理(配置到xml中)
2.4 通过ClassPathXmlApplicationContext来加载spring的配置文件生成BeanFactory工厂对象,通过工厂对象来创建所需要的bean
hibernate框架搭建
1.1 加入jar包
HIBERNATE_HOME/hibernate3.jar -- hibernate核心包
HIBERNATE_HOME/lib/required/*.jar
(在hibernate官网下载的包中却少一个必须包slf4j-nop-1.5.2.jar,需要自己在网上下载)
数据库的jar包
1.2 hibernate.cfg.xml配置文件
HIBERNATE_HOME/project/etc/hibernate.cfg.xml
对应属性在HIBERNATE_HOME/project/etc/hibernate.properties中寻找
hibernate.connection.url --- 访问数据库的url地址
hibernate.connection.username --- 访问数据库的用户名
hibernate.connection.password --- 访问数据库的密码
hibernate.connection.driver_calss --- 访问数据库所需的驱动包
hibernate.dialect --- 访问数据库的方言
1.3 Xxxx.hbm.xml 映射文件
HIBERNATE_HOME/project/tutorials/eg/src/main/java/org/hibernate/auction/Xxxx.hbm.xml
将该文件以需要映射的类的类名.hbm.xml命名放在跟映射类同包中
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)