部署NullPointer后的CDI拦截器Glassfish

时间:2012-09-27 20:11:58

标签: java-ee deployment glassfish-3 cdi interceptor

我第一次玩glassfish 3.1。

创建META-INF\beans.xml文件后,部署失败。

@WebServlet

@Override
@Audit
protected void service(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {
    PrintWriter writer = res.getWriter();
    writer.write("Hello!");

}

注释@Audit

@Inherited  
@InterceptorBinding  
@Retention(RetentionPolicy.RUNTIME)  
@Target({ElementType.METHOD, ElementType.TYPE}) 

public @interface Audit {
}

审计实施

@Interceptor
@Audit
public class AuditImpl {
     @AroundInvoke  
     public Object auditting(InvocationContext context) throws Exception {  
     System.out.println("Log before method call...");  
     Object returnObject = context.proceed();  
            // to do some logging  
     System.out.println("Log after method call...");  
     return returnObject;  
     } 
}

META-INF / beans.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
 <interceptors>
    <class>xyz.AuditImpl</class>
 </interceptors>
</beans>

我不知道在Glassfish中查找错误详细信息的位置。 请帮忙。

部署错误:

[#|2012-09-27T21:43:31.010+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=55;_ThreadName=Thread-1;|Exception while invoking class org.glassfish.weld.WeldDeployer load method
java.lang.NullPointerException
    at org.glassfish.weld.BeanDeploymentArchiveImpl.handleEntry(BeanDeploymentArchiveImpl.java:489)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.collectJarInfo(BeanDeploymentArchiveImpl.java:473)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.populate(BeanDeploymentArchiveImpl.java:413)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.<init>(BeanDeploymentArchiveImpl.java:148)
    at org.glassfish.weld.BeanDeploymentArchiveImpl.<init>(BeanDeploymentArchiveImpl.java:128)
    at org.glassfish.weld.DeploymentImpl.<init>(DeploymentImpl.java:120)
    at org.glassfish.weld.WeldDeployer.load(WeldDeployer.java:334)
    at org.glassfish.weld.WeldDeployer.load(WeldDeployer.java:99)
    at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)
    at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:249)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:360)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1067)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1247)
    at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:145)
    at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:577)
    at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:463)
    at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:395)
    at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:380)
    at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:213)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
|#]

[#|2012-09-27T21:43:31.010+0200|SEVERE|glassfish3.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=55;_ThreadName=Thread-1;|Exception while loading the app|#]

[#|2012-09-27T21:43:31.016+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=55;_ThreadName=Thread-1;|Exception while loading the app|#]

1 个答案:

答案 0 :(得分:1)

我已经清除了在glassfish服务器中出现的所有应用程序,并且在重新启动和新部署之后,应用程序正常运行。

BTW:当我使用EJB方法时调用我的@Audit拦截器,@ WebServlet方法是我的拦截器没有被调用。我将发布新问题。