在同一个应用程序中,我有几个项目具有大致的结构:
我使用Maven解决所有依赖关系,也将所有东西很好地捆绑到WAR中,然后我将其部署在JBoss上。
我的问题是,我的大部分模型都在ejb项目中,并且我需要Backing Bean逻辑中(在Web中)或在JSF .xhtmls中(在Web中)直接调用这些bean。
我搜寻了Internet,包括堆栈溢出,并在SPRING上找到了大量示例,以及如何导入/导出模块。好吧,由于我没有使用它,所以我不知道如何继续进行下去。
那么,如何从另一个项目中导入/使用这些bean?
任何帮助表示赞赏!
由于您使用的是您提到的技术堆栈,因此最好也使用CDI。无论如何,如果将所有内容打包为WAR,则在运行时只是一个模块。假设您具有以下结构:
--- WAR
|--- any *.xhtml files can live here (public)
|--- WEB-INF
|--- web.xml (optional)
|--- persistence.xml (optional) - declare persistence unit used from WEB-INF/classes
|--- beans.xml (optional) enable CDI annotation scanning for WEB-INF/classes
|--- faces-config.xml (optional) enable JSF annotation scanning in WEB-INF/classes
|--- *.xhtml files can live here (private - usually templates, ui:composition, etc.)
|--- classes
|--- com.example - put managed beans here, EJBs, JPA etities or just about any other *.class
|---lib
|--- jpa.jar
|--- META-INF
|--- persistence.xml - persistence unit used in this jar
|--- com.example - JPA entities can live here, gets mapped to WEB-INF/classes at runtime
|--- ejb.jar
|--- META-INF
|--- ejb-jar.xml (optional) but can declare resources here
|--- com.example - ejbs can live here, gets mapped to /WEB-INF/classes at runtime
|--- faces.jar
|--- META-INF
|--- faces-config.xml - enables scanning JSF specific annotations in this jar
|--- resources - this gets mapped to the WAR root at runtime, .xhtml can live here
|--- com.example - put your @ManagedBean s here and @EJB inject anything from ejb.jar, gets mapped to /WEB-INF/classes at runtime
|--- cdi.jar
|--- META-INF
|--- beans.xml - marks this as CDI bean archive
|--- com.example - CDI beans can live here, gets mapped to WEB-INF/classes at runtime
请注意,即使我在上述结构中将jpa.jar,ejb.jar,faces.jar和CDI.jar专门分开,也没有必要说-您可以随意混合和匹配。要点:
WEB-INF/lib
映射到WAR类中的任何jar/WEB-INF/classes
beans.xml
启用CDIfaces-config.xml
启用JSF注释扫描ejb-jar.xml
不需要在任何地方,但是您可以利用它web.xml
可以居住WEB-INF/
,但不是必需的web-fragment.xml
可以放在其中META-INF
任何jar的文件夹中WEB-INF/lib
并合并到web.xml
.xhtml
JSF文件可以驻留在Web应用程序根目录(公共)中,位于WEB-INF/
(私有)内部,也可以位于其中META-INF/resources
的任何jar中WEB-INF/lib
-所有这些文件都映射到Web应用程序根目录(即,WEB-INF/
如果它们在jar中,则它们可以在逻辑上终止于jar中META-INF/resource/WEB-INF
)persistence.xml
可以WEB-INF
住在里面META-INF
的任何罐子里或里面WEB-INF/lib
那应该就可以解决了-如果不清楚或可以添加任何内容,请告诉我。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句