1. 程式人生 > >使用Intellij Idea+Gradle 搭建Java 本地開發環境

使用Intellij Idea+Gradle 搭建Java 本地開發環境

專案搭建採用技術棧為:Spring+Spring MVC+Hibernate+Jsp+Gradle+tomcat+mysql5.6

搭建環境文件目錄結構說明:

  1. 使用Intellj Idea 搭建專案過程詳解
  2. 專案各配置檔案講解及部署
  3. 各層包功能講解&專案搭建完畢最終效果演示圖
  4. 專案中重要程式碼講解
  5. webapp資料夾下分層詳解
  6. 配置tomcat 執行環境

1. 使用Intellj Idea 搭建專案過程詳解

1.1 開啟Intellj Idea


Intellj idea 截圖

1.2 操縱 Intellj Idea 工具欄 新建專案


操縱idea 工具欄
使用Gradle建立專案
完善專案資訊
設定Gradle
確定專案資訊

選擇New Window
初始化專案結構截圖

需要說明的是,最初建立的專案檢視是不完整的,包括webapp資料夾下沒有web.xml,以及src包下缺少Java資料夾(放置java原始碼檔案),Resources資料夾(放置專案配置檔案)。
我們繼續做以下操作,使得專案的結構符合web 應用專案的層級標準。


操縱工具欄為專案新增 web.xml全域性配置檔案

出現如下檢視:


新建 web.xml檔案
設定web.xml檔案儲存位置

接下來:單擊main資料夾按照如下操作:


手動建立src中main資料夾下java目錄
輸入java 資料夾名稱

點選ok,再按照上圖操作操作一遍,輸入檔名為resources
最終的結構圖如下圖所示:


專案最終結構圖

2. 專案各配置檔案講解及部署

完成了專案的初始化結構建立,接下來我們需要來建立配置檔案。
首先是resources資料夾下的配置檔案
2.1 resources下資原始檔截圖:(最終配置的結果)


專案所需配置檔案最終配置結果


2.2 data-access-applicationContext.xml
主要管理資料庫訪問元件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beansxmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context.xsd
  9. ">
  10. <!-- 配置自動掃描的包 -->
  11. <context:component-scanbase-package="com.fxmms"use-default-filters="false">
  12. <context:include-filtertype="regex"expression="com.fxmms.*.*.dao.*"/>
  13. <context:include-filtertype="regex"expression="com.fxmms.*.dao.*"/>
  14. </context:component-scan>
  15. <!-- 配置資料來源 -->
  16. <context:property-placeholderlocation="classpath:db.properties"/>
  17. <beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  18. <propertyname="driverClassName"value="${jdbc.driverClass}"/>
  19. <propertyname="url"value="${jdbc.jdbcUrl}"/>
  20. <propertyname="username"value="${jdbc.user}"/>
  21. <propertyname="password"value="${jdbc.password}"/>
  22. </bean>
  23. <!--配置hibernate SessionFactory-->
  24. <beanid="sessionFactory"
  25. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  26. <propertyname="dataSource"ref="dataSource"></property>
  27. <propertyname="hibernateProperties">
  28. <props>
  29. <propkey="hibernate.dialect">${dataSource.hibernate.dialect}</prop>
  30. <propkey="hibernate.show_sql">${dataSource.hibernate.show_sql}</prop>
  31. <propkey="hibernate.format_sql">true</prop>
  32. <!--負責自動建立資料表,基本上不能開啟註釋,否則所有的資料庫中表資訊都會被刪除,重新建立-->
  33. <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> -->
  34. </props>
  35. </property>
  36. <!-- <property name="hibernate.jdbc.batch_size" value="50"></property> -->
  37. <propertyname="packagesToScan">
  38. <list>
  39. <value>com.fxmms.*.*.domain</value>
  40. <value>com.fxmms.*.domain</value>
  41. </list>
  42. </property>
  43. </bean>
  44. <!--jdbcTemplate start -->
  45. <beanid="jdbcTemplate"class="org.springframework.jdbc.core.JdbcTemplate">
  46. <propertyname="dataSource"ref="dataSource"></property>
  47. </bean>
  48. <!--Spring JDBC 中操作 LOB 資料 -->
  49. <beanid="lobHandler"class="org.springframework.jdbc.support.lob.DefaultLobHandler"
  50. lazy-init="true"></bean>
  51. <!-- 配置JPA部分 -->
  52. <!-- 配置JPA的EntityManagerFactory -->
  53. <!-- <bean id="entityManagerFactory"
  54. class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  55. <property name="dataSource" ref="dataSource"></property>
  56. <property name="jpaVendorAdapter">
  57. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></bean>
  58. </property>
  59. <property name="packagesToScan" value="com.fxmms"></property>
  60. <property name="jpaProperties">
  61. <props>
  62. <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
  63. <prop key="hibernate.hbm2ddl.auto">update</prop>
  64. <prop key="hibernate.show_sql">true</prop>
  65. <prop key="hibernate.format_sql">true</prop>
  66. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
  67. <prop key="hibernate.cache.use_second_level_cache">true</prop>
  68. <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory
  69. </prop>
  70. <prop key="hibernate.cache.use_query_cache">true</prop>
  71. </props>
  72. </property>
  73. <!–使用二級快取–>
  74. <property name="sharedCacheMode" value="ENABLE_SELECTIVE"></property>
  75. </bean>
  76. <!– 配置事務 –>
  77. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
  78. <property name="entityManagerFactory" ref="entityManagerFactory"></property>
  79. </bean>-->
  80. <!-- <!– 配置SpringData部分 –>
  81. <jpa:repositories base-package="com.fxmms"
  82. entity-manager-factory-ref="entityManagerFactory">
  83. </jpa:repositories>-->
  84. </beans>

2.3 service-applicationContext.xml
主要管理業務邏輯元件,包括對資料庫訪問的事務控制,以及定時任務。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beansxmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:task="http://www.springframework.org/schema/task"
  7. xmlns:tx="http://www.springframework.org/schema/tx"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  10. http://www.springframework.org/schema/aop
  11. http://www.springframework.org/schema/aop/spring-aop.xsd
  12. http://www.springframework.org/schema/tx
  13. http://www.springframework.org/schema/tx/spring-tx.xsd
  14. http://www.springframework.org/schema/task
  15. http://www.springframework.org/schema/task/spring-task.xsd">
  16. <aop:aspectj-autoproxy/>
  17. <!--設定定時任務-->
  18. <task:annotation-driven/>
  19. <context:component-scanbase-package="com.fxmms.www"use-default-filters="false">
  20. <context:include-filtertype="annotation"

    相關推薦

    使用Intellij IdeaGradle 搭建Java 本地開發環境

    專案搭建採用技術棧為:Spring+Spring MVC+Hibernate+Jsp+Gradle+tomcat+mysql5.6搭建環境文件目錄結構說明:使用Intellj Idea 搭建專案過程詳解專案各配置檔案講解及部署各層包功能講解&專案搭建完畢最終效果演示圖

    「問題解決」利用IntelliJ IDEA搭建Java Web開發環境

    為了應對今年火燒眉毛的春招與秋招,最近開始學習JavaWeb開發。 在進行JavaWeb應用開發前,需要先把整個開發環境搭建好。例如,需要安裝Java開發工具包JDK、Web伺服器(Tomcat)和IDE開發工具。 本人最近學習的書籍中,是利用Eclipse作為JavaWeb應用開發工具。由

    使用IntelliJ IDEA和maven搭建java web項目

    生成 cat maven 原始的 cti intel tid rec 工程 File -> New Module,進入創建項目窗口。 點擊Next,填寫GroupId、ArtifactId和Version 填寫Module name,要保證maven中央倉

    搭建 Java Web 開發環境

      此實驗教大家如何配置 JDK 、Tomcat 和 Mysql 安裝 JDK JDK 是開發Java程式必須安裝的軟體,檢視一下 yum 源裡面的 JDK: yum list java* 選擇適合本機的JDK,並安裝: yum install

    搭建Java Web 開發環境

    說明: 本教程中使用的騰訊雲,IP地址是http://123.207.7.49:8080 ,這些設定可能會有所不同,你需要根據不同情況進行修改。 1.啟動伺服器進入雲主機,可以看到以下畫面! 2. 安裝 JDK JDK 是開發Java程式必須安裝的軟體,我們

    Centos下Docker使用映象和DockerFile方式搭建JAVA Web 開發環境

    1、環境1、1先決條件1.必須是64位CPU架構的計算機,Docker目前不支援32位CPU;2.執行Linux3.8或更高版本核心,CentOS時核心必不小於3.10;3.核心必須支援一種合適的儲存驅動,可以是Device Manager、AUFS、vfs、btrfs、以及

    mac搭建java web開發環境

    新入手mac筆記本,需要重新搭建java開發環境。 之前一直使用的環境: myeclipse(自帶各種外掛) weblogic oracle 本次在mac上準備搭建的環境: ecplise(官網下載,注意有多個版本,下載《Eclipse IDE for Java EE De

    開發環境-Windows下搭建JAVA Web開發環境(含Tomcat+MySQL)-過程記錄

    一、新建雲伺服器 (請注意,文中連結均在“http”中“h”後和“www”第一個“w”後多加一“ ”)     1、在"teng xun 雲",新建雲伺服器:Windows Server 2012 R2 標準版 64位中文版     2、登入雲伺服器:h ttps://w

    Linux下搭建Java web開發環境

    概述: 1.Linux環境一臺(VM或者雲伺服器,本教程採用百度雲伺服器BCC)Baidu Cloud Compute 伺服器配置說明:centos6.5,jdk7_64 ,tomcat7 2.新建幾個目錄,/software /data /log /backup,用來存放jdk、t

    配置IntelliJ IDEA 13的SBT和Scala開發環境

    對於scala的開發環境,公認最好的IDE是IntelliJ IDEA+scala&sbt外掛。sbt(Simple Build Tool,a build tool for Scala.)是scala專用的構建工具,使用scala語言編寫,配置比maven等構建工具

    Mac OS X 10.9下搭建java web開發環境之一 開啟和配置本機的Apache服務

    概要: 可能大多數人沒有注意到,Mac OS X 其實內建了 Apache 伺服器,可以很簡單的啟動web服務。Apple 將 Apache “封裝”起來了,通常的使用者介面中沒有任何直接對其進行操作設定的部分。本文簡介Mac OS X 中怎樣通過Apache啟動web服務

    Java Web學習(3):Win7 64位作業系統搭建Java Web開發環境

            一搭建Java Web開發環境的總體概覽        工欲善其事必先利其器。學會搭建Java Web開發環境是學習JSP動態網站開發的最基本技能之一。主要介紹在 Windows 7

    初學Java Web(2)——搭建Java Web開發環境

    config 官方網站 thead .com view eve 微信 停止 記錄 初學Java Web(2)——搭建Java Web開發環境 雖然說 html 和 css 等前端技術,是對於 Web 來說不可或缺的技術,但是

    Hadoop Intellij IDEA本地開發環境搭建

    首先我們需要新建一個java工程用於開發Mapper與Reducer,同時我們也需要匯入hadoop的依賴包,這些包可以在hadoop的 share/hadoop 目錄下找到,你可以把這些包單獨取出來作為之後專案的備用。 開啟Project Structure

    IDEA如何快速搭建Java開發環境,IntelliJ IDEA mac新手入門

    images jdk版本 color port servers 技術分享 -o 本地倉庫 serve 作為IntelliJ IDEA mac新手,IDEA如何快速搭建Java開發環境呢?今天小編就給大家帶來了IntelliJ IDEA mac使用教程,想知道IDEA如何快速

    JAVA 基礎--開發環境IDEA 搭建

    com target 註冊碼 獲取 nbsp activate 配置 選擇 ref 1.下載IDEA (500M+) 2.激活。 在網站http://idea.lanyus.com/中獲取註冊碼,填入Activation code中; 然後點擊Activate即可

    Spark本地開發環境配置(windows/Intellij IDEA 篇)

    前言 Intellij IDEA是一個蠻不錯的IDE,在java/scala領域深得人心。筆者之前使用的是Eclipse那一套開發環境,雖然也不錯,但忍不住好奇心的驅使,折騰了一下IDEA,將自己摸索過程總結一下,方便Spark愛好者參考。 1.配置前提 J

    搭建struts2 專案開發環境——(使用Intellij IDEA+Maven+struts2 )

    Struts的介紹        Struts的是阿帕奇軟體基金會(ASF)贊助的一個開源專案。它最初是雅加達專案中的一個子專案,並在2004年3月成為ASF的頂級專案。它通過採用JavaServlet / JSP技術,實現了基於JavaEEWeb應用的M

    利用Intellij Idea在windows搭建spark 開發環境(含打jar包過程)(一)

    本文的目的:利用Intellij Idea在windows搭建spark 開發環境 環境:windows 10, intellij idea2016.1.1, spark 1.6.2(HDP),hadoop2.7.3(HDP),scala 2.10.5(編譯環境), sbt

    使用IDEAgradle搭建Spring MVC和MyBatis開發環境

    1. 概述 Gradle是一個基於Apache Ant和Apache Maven概念的專案自動化建構工具。 它使用一種基於Groovy的特定領域語言(DSL)來宣告專案設定,拋棄了基於XML的各種繁瑣配置。 Spring MVC屬於SpringFrameWork的後續產品,已經融合 在Spring W