2011-05-04 56 views
13

我們正在使用Spring,Sping MVC和Hibernate開始一個新的Java EE web應用程序。我們很可能也會使用maven。j2ee web應用程序的標準項目/包結構

在開始之前,我們需要爲Web應用程序提供項目/包結構。

什麼是Java EE Web應用程序的標準項目/包結構?

它還應該在所有應用程序服務器上運行,而不對項目結構或任何配置文件進行任何更改。

我們將使用Spring源代碼版本2.6.0(最新版本)。

任何想法?

回答

21

如果您使用的是maven,最好遵循標準的maven項目佈局。您可以從選項

這會給你一個包結構如表得到行家做,產生這種結構對你來說,

mvn archetype:generate 

和選擇彈簧-MVC-JPA的原型,

├── pom.xml 
    └── src 
     ├── main 
     │   ├── java 
     │   │   └── mygroup 
     │   │    ├── controller 
     │   │    │   ├── HomeController.java 
     │   │    │   └── PersonController.java 
     │   │    ├── dao 
     │   │    │   └── PersonDao.java 
     │   │    └── model 
     │   │     └── Person.java 
     │   ├── resources 
     │   │   ├── db.properties 
     │   │   ├── log4j.xml 
     │   │   └── META-INF 
     │   │    └── persistence.xml 
     │   └── webapp 
     │    ├── index.html 
     │    ├── META-INF 
     │    │   ├── context.xml 
     │    │   └── MANIFEST.MF 
     │    ├── resources 
     │    │   └── css 
     │    │    └── screen.css 
     │    └── WEB-INF 
     │     ├── spring 
     │     │   ├── app 
     │     │   │   ├── controllers.xml 
     │     │   │   └── servlet-context.xml 
     │     │   ├── db.xml 
     │     │   └── root-context.xml 
     │     ├── views 
     │     │   ├── edit.jsp 
     │     │   ├── home.jsp 
     │     │   └── list.jsp 
     │     └── web.xml 
     └── test 
      ├── java 
      │   └── mygroup 
      │    ├── controller 
      │    │   ├── DataInitializer.java 
      │    │   ├── HomeControllerTest.java 
      │    │   └── PersonControllerTest.java 
      │    └── dao 
      │     └── PersonDaoTest.java 
      └── resources 
       ├── db.properties 
       ├── log4j.xml 
       ├── test-context.xml 
       └── test-db.xml 
+0

嗨。謝謝回覆。我嘗試過,但我們不會使用ejb的等等東西。除此之外,我如何構建我的類,即彈簧控制器,模型,道奇,服務,業務邏輯,各種接口等? – ashishjmeshram 2011-05-04 05:26:41

+1

更新了我的答案,使用spring-mvc-jpa-archetype – sbridges 2011-05-04 05:36:26

11

常見的,更完整的Java包的MVCSR結構(模型,視圖,控制器,服務,信息庫)的Web應用程序就會是這樣的:

java 
└── com 
    └── youdomain 
     | 
     ├── base // broadly used app-wide base and abstract classes) 
     | 
     ├── core // broadly, scattered use helpers, utilities, app health/stats 
     |   // tracking, logging, etc 
     | 
     ├── controller // Fields Http/CGI requests and drives/initiates request 
     |   // comprehension, validation, security checks, requesting 
     |   // operations by the Service module and invoking the View to 
     |   // generate a response. 
     | 
     ├── data // This is the lower level data infrastructure, with several 
     |   //packages under it for mappers, schema tables/enums, helpers, 
     |   // record location, id management, etc 
     | 
     ├── domain // app-wide exposed classes, managers, and interfaces to 
     |   // each persisted (usually DB) domain 'object'. Each 
     |   // object often correlates to one table row in you DB. 
     |   // Domain objects are mostly considered data, but have some fundamental 
     |   // record construction, validation, elaboration, and ancillary information 
     |   // functionality which is opaque to the rest of the application. 
     |   // For example: Customer, Account, Purchase, Inventory, 
     |   // Product, Sale, Return, SpecialOffer, FeedbackComment... 
     | 
     ├── repository // more complicated persisted objects, often structured 
     |  // to address certain efficiency or traversal needs, often each 
     |  // repository is underpinned by several records, tables, 
     |  // and even cross-DB structures. Example: 
     |  // -- OrderHistory, 
     |  // -- ProductsGlobalSearchIndex, 
     |  // -- CustomerSpecificProductMarketingSuggestionCorrelates 
     | 
     ├── service // The smarts of the whole application, performs macro, holoistic 
     |  // operations involving multiple DB tables and operations. Such as: 
     |  // -- account.UserAccountLifecycle, 
     |  // -- order.CustomerOrder, 
     |  // -- order.CustomerOrderShipment 
     | 
     └── view // Intefaces with your jsp, freemarker, tapestry etc.