ClassNotFoundException在GlassFish 5.0 Server上部署Java EE应用程序时

时间:2018-01-11 23:59:50

标签: jsf java-ee glassfish jsr354

在部署包含在具有最小实体的WAR的Java EE 7应用程序期间

@Entity
public class MyEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    private Long id;
    @Basic
    @Column(length=8192)
    private CurrencyUnit currencyUnit;

    public MyEntity() {
    }

    public MyEntity(Long id, CurrencyUnit currentyUnit) {
        this.id = id;
        this.currencyUnit = currentyUnit;
    }

    [getter and setter for id and currentyUnit]

和带接口的最小EJB

@Local
public interface InitService {

    MyEntity init();
}

和实施

@Stateless
public class DefaultInitService implements InitService {

    @Override
    public MyEntity init() {
        MyEntity retValue = new MyEntity(1L, Monetary.getCurrency("EUR"));
        return retValue;
    }
}

和支持bean

@Named
@ApplicationScoped
@Eager
public class MyManagedBean {
    @EJB
    private InitService initService;
    private MyEntity myEntity;

    public MyManagedBean() {
    }

    @PostConstruct
    private void init() {
        this.myEntity = initService.init();
    }

    public MyEntity getMyEntity() {
        return myEntity;
    }

    public void setMyEntity(MyEntity myEntity) {
        this.myEntity = myEntity;
    }
}

我在GlassFish 5.0上部署期间遇到以下异常:

Schwerwiegend:   Undeployment failed for context /monteta-clazz-not-found-issue
Schwerwiegend:   Exception while loading the app : CDI deployment failure:Error instantiating :org.hibernate.validator.cdi.internal.ValidationExtension
java.util.ServiceConfigurationError: Error instantiating :org.hibernate.validator.cdi.internal.ValidationExtension
    at org.jboss.weld.util.ServiceLoader.createInstance(ServiceLoader.java:315)
    at org.jboss.weld.util.ServiceLoader.prepareInstance(ServiceLoader.java:247)
    at org.jboss.weld.util.ServiceLoader.loadService(ServiceLoader.java:215)
    at org.jboss.weld.util.ServiceLoader.loadServiceFile(ServiceLoader.java:185)
    at org.jboss.weld.util.ServiceLoader.reload(ServiceLoader.java:165)
    at org.jboss.weld.util.ServiceLoader.iterator(ServiceLoader.java:289)
    at org.glassfish.weld.DeploymentImpl.getExtensions(DeploymentImpl.java:466)
    at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:223)
    at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
    at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:496)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:540)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:536)
    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:535)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:566)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:558)
    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:557)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1465)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:110)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1847)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1723)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
    at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
    at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:190)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jboss.weld.util.ServiceLoader.createInstance(ServiceLoader.java:313)
    ... 48 more
Caused by: java.lang.TypeNotPresentException: Type javax.money.MonetaryAmount not present
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:108)
    at java.lang.Class.getGenericInterfaces(Class.java:913)
    at org.hibernate.validator.internal.util.TypeHelper.resolveTypeForClassAndHierarchy(TypeHelper.java:390)
    at org.hibernate.validator.internal.util.TypeHelper.resolveTypes(TypeHelper.java:351)
    at org.hibernate.validator.internal.util.TypeHelper.extractType(TypeHelper.java:327)
    at org.hibernate.validator.internal.engine.constraintvalidation.ClassBasedValidatorDescriptor.<init>(ClassBasedValidatorDescriptor.java:39)
    at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorDescriptor.forClass(ConstraintValidatorDescriptor.java:49)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.hibernate.validator.internal.metadata.core.ConstraintHelper.putConstraints(ConstraintHelper.java:686)
    at org.hibernate.validator.internal.metadata.core.ConstraintHelper.<init>(ConstraintHelper.java:318)
    at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:155)
    at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:322)
    at org.hibernate.validator.cdi.internal.ValidationExtension.<init>(ValidationExtension.java:116)
    ... 53 more
Caused by: java.lang.ClassNotFoundException: javax.money.MonetaryAmount
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.felix.framework.ExtensionManager$ExtensionManagerWiring.getClassByDelegation(ExtensionManager.java:873)
    at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1553)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1484)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
    ... 78 more

中提供了缺失的类型
<dependency>
    <groupId>javax.money</groupId>
    <artifactId>money-api</artifactId>
    <version>1.0.1</version>
</dependency>
<dependency>
    <groupId>org.javamoney</groupId>
    <artifactId>moneta</artifactId>
    <version>1.0.1-SNAPSHOT</version>
</dependency>

MCVE可在https://gitlab.com/krichter/monteta-clazz-not-found-issue获得。

2 个答案:

答案 0 :(得分:0)

您的org.javamoney:moneta:1.0.1-SNAPSHOT版本似乎不正确。 SNAPSHOT依赖项仅适用于开发人员,但从未发布到Maven Repository。 您可以查看all available versions in Maven Central

所以,要修复只是尝试使用这个:

<dependency>
    <groupId>org.javamoney</groupId>
    <artifactId>moneta</artifactId>
    <version>1.1</version>
</dependency>

答案 1 :(得分:0)

对我来说,解决方法“Money而不是浮点+ CurrencyUnit”不是一个选项,因为即使我使用java.money压缩我的类,错误仍然存​​在。此外,如果我从我的依赖项中删除了hibernate验证器,如果我将它从传递中排除,则错误仍然存​​在。

这样我理解该库已经存在于glassfish类路径中。因为从我那里删除它并不是一个简单的解决方案,因为我还需要在我的应用程序中使用java.money我认为我可以在glassfish类路径中添加java.money并且它有效。我认为这是因为glassfish“delegates”classloader方法使app类加载器委托给服务器类加载器来加载服务器可以加载的所有类。

所以解决方案是我在glassfish安装的lib / endorsed文件夹中添加java.money-api.jar。