【问题标题】:Standard project/package structure of a j2ee web applicationj2ee web 应用程序的标准项目/包结构
【发布时间】:2011-05-04 04:58:08
【问题描述】:

我们正在使用 Spring、Sping MVC 和 Hibernate 启动一个新的 Java EE Web 应用程序。我们很可能也会使用 maven。

在开始之前,我们需要为 Web 应用程序提出项目/包结构。

Java EE Web 应用程序的标准项目/包结构是什么?

它还应该在所有应用服务器上运行,而不需要对项目结构或任何配置文件进行任何更改。

我们将使用 Spring 源 IDE 版本 2.6.0(最新版本)。

有什么想法吗?

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    如果您使用的是 maven,最好遵循标准的 maven 项目布局。你可以让 maven 为你生成这个结构,

    mvn archetype:generate 
    

    并从选项列表中选择 spring-mvc-jpa-archetype

    这会给你一个像这样的包结构,

      ├── 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
    

    【讨论】:

    • 嗨。谢谢回复。我试过了,但我们不会使用 ejb 之类的东西。除此之外,我如何构建我的类,即 spring 控制器、模型、daos、服务、业务逻辑、各种接口等?
    【解决方案2】:

    用于 MVCSR(模型、视图、控制器、服务、存储库)Web 应用程序的通用、更完整的 Java 包结构类似于:

    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.
    

    【讨论】:

      猜你喜欢
      • 2017-06-03
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 2016-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多