有一个带有多个模块的Maven项目。 有一个类应该具有相同的行为 除了一个模块以外的所有模块:
@Default
public class DefaultClassLoader {
...
public String whoAmI(){
return "Default";
}
@Retry(maxRetries = Integer.MAX_VALUE, delayUnit = ChronoUnit.SECONDS, delay = 5, retryOn = WebApplicationException.class)
@Asynchronous
@AccessTimeout(value = Long.MAX_VALUE)
public void load(String moduleName, AboveIt aboveIt) {
....
}
}
一个 @Specializes 覆盖的默认类:
@Specializes
public class SpecificClassLoader extends DefaultClassLoader {
@Override
public String whoAmI(){
return "Specific";
}
@Retry(maxRetries = Integer.MAX_VALUE, delayUnit = ChronoUnit.SECONDS, delay = 5, retryOn = WebApplicationException.class)
@Asynchronous
@AccessTimeout(value = Long.MAX_VALUE)
public void load(String moduleName, AboveIt aboveIt) {
#This is working well
#Using somethingToSet instance
...
}
}
最后,使用 DefaultClassLoader 的类:
@Singleton
@Startup
public class AboveIt {
...
@Inject
private DefaultClassLoader defaultClassLoader;
@PostConstruct
public void load() {
System.out.println(defaultClassLoader.whoAmI());
System.out.println(defaultClassLoader);
defaultClassLoader.load(moduleName, this);
}
...
}
类 DefaultClassLoader 和 AboveIt 存储在.jar的模块构建中,许多其他模块使用由payara服务器部署到.war的内置文件。 SpecificClassLoader 类存储在该特定模块的目录结构中。
每次都可以调用 AboveIt 类中的 System.out.println(defaultClassLoader) ,但是可以调用 defaultClassLoader.load(模块名称,此) 仅适用于SpecificClassLoader。
在Payara的ServerLog中 System.out.println(defaultClassLoader) 的结果 部署一个特定模块时:[path].SpecificClassLoader@3d6bf268
System.out.println(defaultClassLoader) 的结果,并部署了其他模块:
[path].DefaultClassLoader$Proxy$_$$_WeldSubclass@2054826f
并因此导致下一行异常( defaultClassLoader.load(moduleName,this) ):
Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton AboveIt
javax.ejb.CreateException: Initialization failed for Singleton AboveIt
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:564)
at com.sun.ejb.containers.AbstractSingletonContainer.access$000(AbstractSingletonContainer.java:78)
at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:734)
at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:438)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:219)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:180)
at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:158)
at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:169)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:123)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:294)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:357)
at com.sun.enterprise.v3.server.ApplicationLifecycle.initialize(ApplicationLifecycle.java:535)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:542)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:557)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:553)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:552)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:583)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:575)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:574)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1483)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:119)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1865)
at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:149)
at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:532)
at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:437)
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:371)
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:362)
at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:231)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceException: Retry failed
at fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy.processRetryStage(FaultTolerancePolicy.java:386)
at fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy.processFallbackStage(FaultTolerancePolicy.java:326)
at fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy.processAsynchronousStage(FaultTolerancePolicy.java:281)
at fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy.proceed(FaultTolerancePolicy.java:268)
at fish.payara.microprofile.faulttolerance.cdi.FaultToleranceInterceptor.intercept(FaultToleranceInterceptor.java:79)
at sun.reflect.GeneratedMethodAccessor814.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
at eu.inloop.mcore.common.DefaultClassLoader$Proxy$_$$_WeldSubclass.load(Unknown Source)
at eu.inloop.mcore.common.AboveIt.load(AboveIt.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.BeanCallbackInterceptor.intercept(InterceptorManager.java:1047)
at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:206)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.init(SystemInterceptorProxy.java:125)
at sun.reflect.GeneratedMethodAccessor623.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:998)
at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
at com.sun.ejb.containers.interceptors.CallbackInvocationContext.proceed(CallbackInvocationContext.java:206)
at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:81)
at org.jboss.weld.module.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
at sun.reflect.GeneratedMethodAccessor621.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.CallbackInterceptor.intercept(InterceptorManager.java:998)
at com.sun.ejb.containers.interceptors.CallbackChainImpl.invokeNext(CallbackChainImpl.java:72)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:417)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:380)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:2087)
at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:555)
... 39 more
]]
添加 @Alternative 以及 @Specializes 表示法,并且未在bean.xml中列出救命。 我知道注入的 defaultClassLoader 错误。为什么 Proxy 有东西? Java EE中的 Proxy 是什么意思?如何解决该问题才能使其正常工作?