标签: java-ee-6

EjbConetxt setRollbackOnly 与 ApplicationException rollback true

我有一个方法可以抛出应用程序异常,回滚为 true。我想知道是否必须显式调用 ejbContext.setRollbackOnly() ?

这里的文档说,当异常标记为 rollback=true 时,我们不需要调用 EjbContext 的 setRollbackOnly 。

就我而言,我捕获了一个 ApplicationException,其回滚属性设置为 true。然后我显式调用 ejbContext.setRollbackOnly(),因为我在 catch 块中抛出了另一个异常,并且该异常将传播到客户端。下面是我的代码片段

try {
   ....
} catch (XYZDirectoryException e) { // ApplicationException marked as rollback=true
   ejbContext.setRollbackOnly();  // Is this necessary?
   // log exception trace
   throw new ServerInternalException("Something bad happened. Please try again or contact administrator. Check logs for more details"); // ApplicationException marked as rollback=false
}
Run Code Online (Sandbox Code Playgroud)

java transactions java-ee-6

2
推荐指数
1
解决办法
2886
查看次数

Spring - Bean创建中的StackOverflowError

我收到以下错误:

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:203)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.MethodInvokingFactoryBean#0' defined in class path resource [common-application-context.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot resolve reference to bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' while setting bean …
Run Code Online (Sandbox Code Playgroud)

java stack-overflow spring dependency-injection java-ee-6

1
推荐指数
1
解决办法
1万
查看次数

我是否需要框架来补充Java EE 6,JSF-2 Web-App?哪个?

在以前的J2EE版本中,通常的做法是使用Spring,Hibernate,Struts等框架来补充默认库
.Java EE 6似乎缩小了差距(使用CDI,JPA,JSF2.0等) - 我应该仍然使用额外的框架(Seam?面对库?Spring?)

我目前正在使用默认的Oracle堆栈 - GlassFish v3,JSF(Mojarra)2.0

java frameworks java-ee-6 jsf-2

1
推荐指数
1
解决办法
898
查看次数

禁用复制粘贴功能啊:inputTextarea标签JSF(2.0)

我的一个客户不希望其他网站复制粘贴具体textArea的内容.目前我有一个inputTextArea为readonly ="true",但我仍然需要禁用复制和粘贴功能.有任何想法吗?

java jsf java-ee java-ee-6 jsf-2

1
推荐指数
1
解决办法
3956
查看次数

这个jpql查询出了什么问题?(JPA)

你能帮我找一下我的应用程序中登录方法的JPQL查询中的错误吗?

// Login
public boolean saveUserState(String email, String password) {
    // 1-Send query to database to see if that user exist
    Query query = em
            .createQuery("SELECT r FROM Role r WHERE r.email=:emailparam r.password=:passwordparam");
    query.setParameter("emailparam", email);
    query.setParameter("passwordparam", password);
    // 2-If the query returns the user(Role) object, store it somewhere in
    // the session
    Role role = (Role) query.getSingleResult();
    if (role != null && role.getEmail().equals(email)
            && role.getPassword().equals(password)) {
        FacesContext.getCurrentInstance().getExternalContext()
                .getSessionMap().put("userRole", role);
        // 3-return true if the user state was saved
        return true; …
Run Code Online (Sandbox Code Playgroud)

java sql jpa jpql java-ee-6

1
推荐指数
1
解决办法
2321
查看次数

Faces Navigation在JSF2中没有真正起作用

我正在使用JSF 2.0

这是我的faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is not required if you don't need any extra configuration. -->
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">

    <navigation-rule>
        <from-view-id>/pages/test/test.html</from-view-id>
        <navigation-case>
            <from-outcome>write</from-outcome>
            <to-view-id>/pages/test/test-write.html</to-view-id>
        </navigation-case>

    </navigation-rule>

</faces-config>
Run Code Online (Sandbox Code Playgroud)

TestController.java

@ManagedBean(name="testController")
@SessionScoped
public class TestController implements Serializable {

    private static final long serialVersionUID = -3244711761400747261L; 

    public String test() {


        return "write?faces-redirect=true";
}
Run Code Online (Sandbox Code Playgroud)

在我的test.xhtml文件中

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    template="/WEB-INF/templates/default.xhtml">
    <ui:define name="content">
            <h:form>
                    <h:commandButton action="#{testController.test()}" value="test" />  
            </h:form>
    </ui:define>

</ui:composition>
Run Code Online (Sandbox Code Playgroud)

这是我的web.xml

<web-app …
Run Code Online (Sandbox Code Playgroud)

navigation faces-config java-ee-6 jsf-2

1
推荐指数
1
解决办法
7885
查看次数

JPA延迟加载JSF视图中的集合 - 比使用过滤器更好的方法?

目前我正在使用事务视图模式在视图中对集合进行延迟加载.

我在web.xml中有以下内容

<filter>
  <filter-name>view</filter-name>
  <filter-class>com.jasoni.ViewFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>view</filter-name>
  <url-pattern>*.xhtml</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

Filter类有以下内容......

public class ViewFilter implements Filter {
  @Resource UserTransaction tx;

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    try {
      tx.begin();
      chain.doFilter(request, response);
    }
    //catch here
    finally {
      //another try-catch
      tx.commit();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

假设我有以下(相当做作的)支持bean

@ManagedBean
@RequestScoped
public class DepartmentEmployees {
  @EJB
  private DepartmentServiceBean deptService;
  @ManagedProperty(value="#{param.deptId}")
  private Integer deptId;
  private Department dept;

  @PostConstruct
  public String init() {
    dept = deptService.findById(deptId);
  }
}
Run Code Online (Sandbox Code Playgroud)

我可以在我的视图中执行类似的操作(.xhtml文件)

<ul>
<c:forEach var="emp" …
Run Code Online (Sandbox Code Playgroud)

java-ee-6 jsf-2 jpa-2.0

1
推荐指数
1
解决办法
5099
查看次数

DAO和服务层设计

我正在使用Java EE 6开发Web应用程序.为了最大限度地减少对数据库的调用,最好有一个类:

数据访问类(DAO)将只调用基本方法getAllClients, getAllProducts, getAllOrders, delete, update方法--CRUD方法.

服务类将调用CRUD方法,但另外还有过滤方法,例如findClientByName, findProuctByType, findProductByYear, findOrderFullyPaid/NotPaidetc ...将基于基本的DAO方法.

谢谢

java java-ee-6

1
推荐指数
1
解决办法
3953
查看次数

Java EE6应用程序需要哪些库(或单个jar)?

  1. 我想知道运行基本EE6应用程序需要jars库吗?
  2. 什么是EAR图书馆?我在哪里可以找到这些罐子的成分列表?
  3. 什么是Web App库?我在哪里可以找到这些成分罐的清单?

java-ee-6

1
推荐指数
1
解决办法
269
查看次数

JEE6:备用EJB声明

我正在使用带有CDI的JBoss 7.1.1.

我在JNDI中有一个名为ServiceAccount的无状态bean.这是真正的服务实现.我有另一个名为ServiceAccountMock的Statelss bean,它是一个Mock服务.两者都来自同一个界面,并打包在service.ear中.

我想要做的是在bean.xml中声明模拟服务作为替代,重新​​部署我的服务,然后所有客户端都看到模拟版本(在客户端没有改变任何东西).

当我部署我的service.ear时,JBoss说:

java.lang.IllegalArgumentException: JBAS011046: A component named 'ServiceAccount' is already defined in this module
Run Code Online (Sandbox Code Playgroud)

这是事实,两种服务都以相同的方式声明(@Stateless(name ="ServiceAccount")).

如果我更改模拟版本的名称,我必须在客户端更改使用哪个EJB(我不想这样做).

有谁知道这是怎么做到的吗 ?

cdi ejb-3.0 java-ee-6 jboss7.x

1
推荐指数
1
解决办法
4549
查看次数