Hibernate
版本:hibernate-release-4.3.8.Final
核心jar包:\lib\required
antlr-2.7.7
dom4j-1.6.1
hibernate-commons-annotations-4.0.5.Final
hibernate-core-4.3.8.Final
hibernate-jpa-2.1-api-1.0.0.Final
jandex-1.1.0.Final
javassist-3.18.1-GA
jboss-logging-3.1.3.GA
jboss-logging-annotations-1.2.0.Beta1
jboss-transaction-api_1.2_spec-1.0.0.Final
配置文件:
XML配置方式——hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.OracleDialect</property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> <property name="connection.username">bin</property> <property name="connection.password">123</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <property name="format_sql">true</property> <!-- mapping setting --> <mapping resource="lg0001/model/bean/account.hbm.xml"/> <mapping class="lg0001.model.bean.Company"/> <mapping class="lg0001.model.bean.Rolelimit"/> </session-factory> </hibernate-configuration>
属性配置方式——hibernate.properties
dialect=org.hibernate.dialect.OracleDialect connection.driver_class=oracle.jdbc.driver.OracleDriver connection.url=jdbc:oracle:thin:@localhost:1521:orcl connection.username=bin connection.password=123 show_sql=true format_sql=true
工具类:HibernateUtil.java
package util; import org.hibernate.SessionFactory; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { SessionFactory sf = null; try { Configuration cfg = new Configuration();//加载 properties配置 cfg.configure();//加载xml配置,默认寻找名为hibernate.cfg.xml的配置文件 ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build(); sf = cfg.buildSessionFactory(sr); } catch (Throwable e) { System.err.println("Initial SessionFactory creation failed!" + e); throw new ExceptionInInitializerError(e); } return sf; } public static SessionFactory getSessionFactory() { return sessionFactory; } }
注意:
1.如果配置文件的文件名是自定义的(例如:hibernate.xml),则需要使用以下方式读取:cfg.configure("hibernate.xml")。
2.Hibernate首先读取属性文件(properties文件)中的配置,再读取xml配置文件中的配置。xml配置覆盖properties配置。
3.属性文件不能配置使用的映射文件。
Spring
版本:3.1.1
核心jar包:
commons-logging-1.1.1
struts2-spring-plugin-2.3.3
org.springframework.aop-3.1.1.RELEASE
…….asm-3.1.1……
beans
context
core
expression
jdbc
orm
transaction
web
配置文件:
spring.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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <bean id="loginAction" class="lg0001.model.action.LoginAction" scope="prototype"> <property name="logic" ref="loginLogic" /> </bean> <bean id="loginLogic" class="lg0001.model.logic.LoginLogic" scope="singleton"> <property name="dao" ref="userDao" /> </bean> <bean id="userDao" class="lg0001.model.dao.LoginDao" scope="singleton" /> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>lg0001/lg0001.jsp</welcome-file> </welcome-file-list> </web-app>
Struts2
版本:struts-2.3.16.3
核心jar包:\apps\struts2-blank\WEB-INF\lib
asm-3.3
asm-commons-3.3
asm-tree-3.3
commons-fileupload-1.3.1
commons-io-2.2
commons-lang3-3.1
commons-logging-1.1.3
freemarker-2.3.19
javassist-3.11.0.GA
log4j-1.2.17
ognl-3.0.6
struts2-core-2.3.16.3
xwork-core-2.3.16.3
配置文件:
struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <constant name="struts.objectFactory" value="spring" /> <include file="buy0001/configurations/struts_buy0001.xml"/> <include file="lg0001/configurations/struts_lg0001.xml"/> </struts>
struts_lg0001.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.objectFactory" value="spring" /> <package name="lg0001" namespace="/lg0001" extends="struts-default"> <action name="doLogin" class="loginAction"> <result name="success" type="redirect"> <param name="location">/in0001/in0001.jsp</param> </result> <result name="error">/lg0001/lg0001.jsp</result> <result name="validateCode" type="stream"> <param name="contentType">image/jpeg</param> <param name="inputName">inputStream</param> </result> </action> </package> </struts>
web.xml的配置见上面Spring部分。
Annotation
所需jar包:\Tomcat7.0\lib
servlet-api
Oracle
核心jar包:\oracle\product\11.2.0\dbhome_1\jdbc\lib
ojdbc6