我只是在想,我什么时候应该真正考虑在 Spring 中加载多个应用程序上下文?到目前为止,我一直在合并上下文文件,<include>以便仅加载一个应用程序上下文。
您是否知道何时在同一 JVM 中使用多个应用程序上下文?
我学会了使用 Java 和 Seam(以及 JSF 1.2)构建 Web 应用程序
但现在我正在使用纯 Java EE 6 和 JSF (Mojara 2.0.9) - 没有任何额外的框架。
在Seam中我使用了forindex.xhtml限制index.page.xml:
<restrict>#{authorizationManager.isAdmin()}</restrict>
Run Code Online (Sandbox Code Playgroud)
有没有像page.xml一样的功能?
并且:
我还使用了index.page.xml拨打一些电话,例如:
<action execute="#{indexController.doSomething()}" on-postback="false"/>
Run Code Online (Sandbox Code Playgroud)
@PostConstruct现在是在控制器中为 .xhtml 执行此操作的唯一机会吗?
另外我如何在没有 的情况下做这样的事情page.xml?
<navigation>
<rule if-outcome="OK">
<redirect view-id="/pages/index.xhtml" />
</rule>
</navigation>
Run Code Online (Sandbox Code Playgroud)
在我看来,纯JavaEE的工作方式完全不同?
(你不必向我发送完整的代码,只需给我我必须谷歌搜索的关键词,谢谢!)
Statele ejb 旨在实现幂等并且不记忆以前的用户交互。对我来说,这听起来像是一个静态方法。
所以而不是有
public void save(Entity e) { em.persist(e); }
Run Code Online (Sandbox Code Playgroud)
安全吗
public static void save(Entity e) { em.persist(e); }
Run Code Online (Sandbox Code Playgroud)
在 EJB 内?
我正在使用 Arquillian 将战争部署到 JBoss 7.x 中进行测试,它依赖于 Apache Commons Collections。然而,它似乎并没有获取模块依赖性。
清单.MF
Dependencies: org.apache.commons.collectionss export
Run Code Online (Sandbox Code Playgroud)
Arquillian 部署
@Deployment
public static Archive<?> createDeployment() {
WebArchive archive = ShrinkWrap.create(WebArchive.class);
archive
.addPackages(true, "com.example.package")
.addAsResource("META-INF/MANIFEST.MF", "META-INF/MANIFEST.MF")
// * Tried the following two options with no luck
//.AddAsManifestResource("META-INF/MANIFEST.MF", "MANIFEST.MF")
//.AddAsWebInfResource("META-INF/MANIFEST.MF", "META-INF/MANIFEST.MF")
// * If I enable the following, it works fine. getLibrary just picks
// * up the lib through maven.
//.addAsLibraries(
// getLibrary("commons-collections:commons-collections:3.2.1"))
;
return archive;
}
Run Code Online (Sandbox Code Playgroud)
我不想使用jboss-deployment-structure.xml,因为感觉就像用大锤敲开坚果。
有任何想法吗?
我有一个 java-ee Web 应用程序,它使用打包为 jar 依赖项(实体类、EJB 存储库、persistence.xml)的持久性单元。
为了让 Web 应用程序运行一些验收测试,我需要覆盖打包的 persistence.xml 中的一个属性。具体来说,我需要通过设置以下属性来禁用默认的活动 eclipselink共享对象缓存。
<property name="eclipselink.cache.shared.default" value="false"/>
Run Code Online (Sandbox Code Playgroud)
这是必要的,因为验收测试是直接使用 dbunit 准备/清理数据库。这些修改将使 eclipselink 缓存处于陈旧状态(因为持久性单元不参与这些修改)。
java-ee(或特定于glassfish)是否有办法覆盖位于jar中的persistence.xml中的属性(从运行我的测试时部署的Web应用程序war文件开始)?
可能还有其他方法,例如构建特定于测试部署的 jar 依赖项,但这条路线对我来说似乎很复杂,因为只覆盖了我的 persistence.xml 中的一个属性。
我刚刚开始玩休眠搜索。我该如何解决以下问题。
我所有的 java 实体都是从超类继承的:
@SuppressWarnings("rawtypes")
@MappedSuperclass
@Indexed
public abstract class BaseEntity{
private Integer id;
private Integer jpaVersion;
private Date creaDate;
private Date modDate;
private String creaUser;
private String modUser;
@Id
@Column(name = "ID", unique = true, nullable = false, precision = 22, scale = 0)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
.....
Run Code Online (Sandbox Code Playgroud)
例如我必须(还有更多)子类:
@Entity
@Indexed
@Table(name = "BASE_PERSON", schema = "MYSCHEMA")
public class Person extends extends BaseEntity{ …Run Code Online (Sandbox Code Playgroud) 我的 JEE 6 应用程序使用 CDI 以及带有嵌入式 tomee (1.7.2) 的 Arquillian 来测试它。在具有多个测试方法的测试类中,同一个 Request Scoped Bean 实例被注入到多个测试方法中。当应用程序部署在独立的 tomee plus 1.7.2 上时,不会出现该问题。
根据arquillian 文档,请求范围的 bean 实例只能用于一种测试方法。不幸的是 tomee 嵌入了自己,Arquillian 文档中没有提到它。这是 tomee 嵌入的已知限制吗?如果没有,如何修复?
服务等级:
@RequestScoped
public class SomeService
{
private String user;
public String execute(final String pNewUser)
{
if(user == null){
user = pNewUser;
}
return user;
}
}
Run Code Online (Sandbox Code Playgroud)
测试级:
@RunWith(Arquillian.class)
public class TestCase
{
@Inject
private SomeService someService;
@Deployment
public static WebArchive createDeployment()
{
return DefaultMicroDeploymenCreator.createDefaultMicroDeplymentWithFileName("TestCase.war");
}
@Test
public void testFirstTestMethod() throws …Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序中记录每个传入请求和传出响应。我正在使用 jee 6,所以我没有 ContainerRequestFilter 和 ContainerResponseFilter 类。所以我决定使用过滤器。
我用 @WebFilter("/*") 注释了一个类并实现了 Filter 接口。我成功读取了请求标头和请求正文。有一些困难,我还阅读了响应标头和响应正文。下面是一个代码片段
MyHttpServletResponseWrapper wrapper = new MyHttpServletResponseWrapper((HttpServletResponse) response);
chain.doFilter(request, wrapper);
Run Code Online (Sandbox Code Playgroud)
MyHttpServletResponseWrapper 类
public class MyHttpServletResponseWrapper extends HttpServletResponseWrapper {
private StringWriter sw = new StringWriter();
public MyHttpServletResponseWrapper(HttpServletResponse response) { super(response); }
public PrintWriter getWriter() { return new PrintWriter(sw); }
public ServletOutputStream getOutputStream() {
return new ServletOutputStream (){
public void write(int B) { sw.append((char) B); }
};
}
public String getCopy() { sw.toString(); }
}
Run Code Online (Sandbox Code Playgroud)
记录响应后,我将响应写回输出流,以便客户端可以接收响应。下面是代码
logResponse(wrapper);
response.getOutputStream().write(wrapper.getCopy().getBytes());
Run Code Online (Sandbox Code Playgroud)
我无法理解的是,如何在阅读后将请求正文放回输入流中。
在 Jersey 等标准 …
我不确定这是一个通用的 JEE6 问题还是一个 Wildfly 10/JBoss7 EAP 实现特定的问题。
我试图将 EJB JNDI 映射中使用的默认 beanName 指定/覆盖为对我更有意义的内容。
例如:
登录管理器Bean:
@Stateless
public class LoginManagerBean extends BaseManagerBean implements LoginManager {
....
}
Run Code Online (Sandbox Code Playgroud)
登录管理器:
@Local
public interface LoginManager{
....
}
Run Code Online (Sandbox Code Playgroud)
在此上下文中,WF10 将自动为此 EJB 创建 JNDI 映射,如下所示:
ejb:myApp/myJar/LoginManagerBean!LoginManager
Run Code Online (Sandbox Code Playgroud)
在EJB 命名约定的 Wildfly 10 文档中,它说对于无状态 bean:
Run Code Online (Sandbox Code Playgroud)ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>......
bean-name :这是您正在查找的 bean 的名称。bean 名称通常是 bean 实现类的非限定类名,但可以通过 ejb-jar.xml 或通过注释进行覆盖。JNDI 名称中的 bean 名称部分不能为空字符串。
但是,我似乎找不到使用哪个注释来指定注释中的 bean 名称。如果我阅读@EJB的文档,它指出该beanName参数是:
此引用映射到的 Enterprise Java Bean 的 ejb 名称
因此,从文档来看,beanName 似乎不是正确使用的参数。
那么如何将映射中的 EJB beanName …
我的JEE应用程序中有2个单例,我想在启动时初始化.像这样的东西:
@Singleton
@Startup
public class ServiceB {
@EJB
private ServiceA a;
@PostConstruct
private void init() {
....
}
}
Run Code Online (Sandbox Code Playgroud)
ServiceB并不真正需要ServiceA,我只是添加了依赖项以确保在ServiceB的init()-Method启动之前完全初始化ServiceA(读取:@ PostConstruct-method finished).
但它不等待.ServiceB实际上在ServiceA之前启动.
有没有办法确保一个Bean的@ PostConstruct-方法等待另一个Bean的@PostConstruct方法完成?
我知道我可以删除ServiceA中的@PostConstruct注释并直接从ServiceB调用它
@PostConstruct init() {
a.init();
}
Run Code Online (Sandbox Code Playgroud)
但我有没有ServiceB的部署.所以我不能依靠ServiceB来初始化ServiceA.ServiceA必须自己做.ServiceB必须等待ServiceA完成.
java-ee-6 ×10
java ×5
jakarta-ee ×3
jpa ×2
apache-tomee ×1
eclipselink ×1
ejb-3.1 ×1
glassfish ×1
hibernate ×1
jboss7.x ×1
jsf-2 ×1
navigation ×1
restrictions ×1
spring ×1
wildfly ×1