<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Spring 3 和 Hibernate 4 集成示例教程 > 原文: [https://howtodoinjava.com/spring-orm/spring3-hibernate4-integration-example/](https://howtodoinjava.com/spring-orm/spring3-hibernate4-integration-example/) 如果您瀏覽了我以前的文章,該文章也是同一主題,即 [**Spring 3 + Hibernate 集成**](https://howtodoinjava.com/spring/spring-orm/spring-3-and-hibernate-integration-tutorial-with-example/) 。 我在那篇文章中收到了很多評論和反饋,其中大部分是因為人們試圖在現有項目中使用代碼/依賴關系,或者他們沒有使用 Maven 來構建項目。 在這兩種情況下,正確識別和使用項目依賴項仍然是主要挑戰。 因此,我決定寫另一篇根本不使用 Maven 的文章。 如果確實如此,我已經在項目源代碼本身中添加了所有必需的 jar 文件。 此外,我具有 Spring 的最新版本,即 3.0.5 至 3.2.5.RELEASE。 [**下載源碼**](https://drive.google.com/file/d/0B7yo2HclmjI4Y3owV0FDaXBvU2c/edit?usp=sharing) ## 1\. 開發環境 1. Eclipse Juno RELEASE 2. JDK 1.6 3. Hibernate 4.0.1 4. Spring 3.2.5.RELEASE 5. MySQL 數據庫 6. Tomcat 7 對于那些直接來到本文的人,讓我們逐步講解 **Spring Hibernate 集成示例**。 ## 2\. 數據庫架構 在開始采取行動之前,請確保您已經使用下表創建了數據庫模式: ```java CREATE TABLE EMPLOYEE ( ID INT PRIMARY KEY AUTO_INCREMENT, FIRSTNAME VARCHAR(30), LASTNAME VARCHAR(30), TELEPHONE VARCHAR(15), EMAIL VARCHAR(30), CREATED TIMESTAMP DEFAULT NOW() ); ``` ## 3\. 創建 Maven Eclipse 動態 Web 項目 這不是困難的一步,而是重要的一步。 請確保您正在創建“Web 應用程序”而不是簡單的“java 項目”。 我已經創建了名稱為`Spring3.2.5Hibernate4.0.1Integration`的項目。 ![Dynamic web project creation in eclipse](https://img.kancloud.cn/9c/7d/9c7d8e7b3afe94b8714ffc27f8f829b7_858x527.jpg) ## 4\. 創建配置 我不會在本節中強調更多,因為我沒有使用上一篇文章中已經存在的新代碼或函數集。 因此,請訪問先前的示例 [**Hibernate+Spring 3 集成示例**](https://howtodoinjava.com/spring/spring-orm/spring-3-and-hibernate-integration-tutorial-with-example/),以獲取更多詳細信息。 由于 Spring 版本的改進,我想在這里給出修改后的配置。 ```java <?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <context:annotation-config /> <context:component-scan base-package="com.howtodoinjava.controller" /> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="classpath:messages" /> <property name="defaultEncoding" value="UTF-8" /> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="employeeDAO" class="com.howtodoinjava.dao.EmployeeDaoImpl"></bean> <bean id="employeeManager" class="com.howtodoinjava.service.EmployeeManagerImpl"></bean> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> </beans> ``` ## 5\. 下載并復制`lib`文件夾中所需的 jar 文件 以前的帖子是關于 Maven 的,所以很多工作似乎都是多余的。 但是,對于使用 ANT 的用戶,他們必須使用下載的 jar。 好吧,這一次,我已經為您完成了這項工作。 以下是此項目中使用的 jar 文件列表。 ```java antlr-2.7.7.jar aopalliance-1.0.jar commons-collections-3.2.1.jar commons-dbcp-1.4.jar commons-lang-2.5.jar commons-logging-1.1.1.jar commons-pool-1.5.4.jar dom4j-1.6.1.jar hibernate-commons-annotations-3.2.0.Final.jar hibernate-core-4.0.1.Final.jar hibernate-jpa-2.1-api-1.0.0.Draft-16.jar javassist-3.12.1.GA.jar jboss-logging-3.1.1.GA.jar jstl-1.2.jar jta-1.1.jar junit-4.11.jar mysql-connector-java-5.1.9.jar slf4j-api-1.6.1.jar spring-aop-3.2.5.RELEASE.jar spring-beans-3.2.5.RELEASE.jar spring-context-3.2.5.RELEASE.jar spring-context-support-3.2.5.RELEASE.jar spring-core-3.2.5.RELEASE.jar spring-expression-3.2.5.RELEASE.jar spring-jdbc-3.2.5.RELEASE.jar spring-orm-3.2.5.RELEASE.jar spring-tx-3.2.5.RELEASE.jar spring-web-3.2.5.RELEASE.jar spring-webmvc-3.2.5.RELEASE.jar standard-1.1.2.jar ``` 將上述所有 jar 文件復制到`lib`文件夾中。 完成此步驟后,您的項目應如下所示: ![spring 3 project hierarchy](https://img.kancloud.cn/33/6f/336f85b55013ca4e11bb15eb23907839_374x509.jpg) spring 3 項目層次結構 ## 6\. Spring Hibernate 集成示例演示 結果將類似于以前的帖子。 為了提醒您,屏幕將如下所示: URL:`http://localhost:8080/Spring3.2.5Hibernate4.0.1Integration/` ![spring 3 + hibernate integration example ](https://img.kancloud.cn/6a/a0/6aa0c88afe347ee854bd1ac6031ae122_663x321.jpg) spring 3 + hibernate 集成示例 [**下載源碼**](https://drive.google.com/file/d/0B7yo2HclmjI4Y3owV0FDaXBvU2c/edit?usp=sharing) 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看