java web应用程序布局,请解释一些设计原则/模式 [英] java web applicaton layout, please explain some design principles/patterns
问题描述
我正在研究这个使用hibernate,jsp和spring框架的java web应用程序。 (从我可以告诉!)
文件布局是这样的:
项目1中的code> classes / com / example / project1 $ /
/ dao
_entity_Dao.java
/ dao / hibernate /
_entity_DaoHibernate.java
/ factory
DaoFactory.java
DaoFactoryImpl.java
/ managers
_entity_Manager.java
/ managers / impl
_entity_ManagerImpl.java
/ model
_entity_ .java
/ service
_xxxx_Service.java
/ service / impl /
_xxxx_ServiceImpl.java
你们有没有读过关于这种布局的地方?这是否被认为是最佳做法?
工厂与经理和服务之间有什么区别? (高级)
对于使用Spring构建的应用程序的典型布局,我会看看随附的示例Web应用程序它(意思是Spring)。
使用DaoFactory这样的东西绝对不是一个好习惯,Daos应该被注入。一般来说,除了一些不常见的情况外,你不应该需要Spring的工厂。注入是在web应用程序启动时完成的,Spring读取配置信息并构造所有对象,并根据配置xml和/或注释插入它们(这假定您的对象为单例作用域,这对于无状态事物通常是这样的daos和服务,作为原型范围的东西获得应用程序要求的新副本)。
在Spring应用程序中,服务类似于无状态会话Bean,它是一个包含用例的应用逻辑的事务层。因此,如果您的用户执行的操作导致几个不同的表得到更新,您可以将daos注入到该服务中,让该服务上的方法对daos进行更新,并配置Spring以将该服务包装在代理,使该方法交易。
我已经看到经理用作我称为服务的另一个名称。这里我不知道他们在做什么。
I'm looking at this java web application that is using hibernate, jsp's, and spring framework. (from what I can tell!)
the file layout is like this:
classes/com/example/project1
inside project1
/dao
_entity_Dao.java
/dao/hibernate/
_entity_DaoHibernate.java
/factory
DaoFactory.java
DaoFactoryImpl.java
/managers
_entity_Manager.java
/managers/impl
_entity_ManagerImpl.java
/model
_entity_.java
/service
_xxxx_Service.java
/service/impl/
_xxxx_ServiceImpl.java
Have you guys read about this sort of layout somewhere? Is it considered best-practice?
What is the difference between a Factory and a Manager and a Service? (high level)
For typical layout of an application built with Spring I'd look at the example web applications that ship with it (meaning Spring).
Using things like DaoFactory is definitely not be a best-practice, the Daos should get injected instead. In general you should not need factories with Spring except for some unusual cases. Injecting is done when the web application starts up, spring reads the configuration information and constructs all the objects and plugs them in according to configuration xml and/or annotations (this is assuming singleton-scope for your objects, which is usual for stateless things like daos and services, things scoped as prototypes get new copies created as the application asks for them).
In Spring applications a service is similar to a Stateless Session Bean, it is a transactional layer encompassing application logic for a use case. So if your user takes an action that has the effect of causing several different tables to get updated you can inject the daos into that service, have a method on that service do the updates on the daos, and configure Spring to wrap that service in a proxy that makes that method transactional.
I've seen manager used as another name for what I described as service. Here I don't know what they're doing with it.
这篇关于java web应用程序布局,请解释一些设计原则/模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!