java.lang.RuntimeException: RESTEASY003325: не удалось создать публичный - PullRequest
0 голосов
/ 16 ноября 2018

Получение следующего исключения при попытке

ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 542) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./rest: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./rest: java.lang.RuntimeException: RESTEASY003325: Failed to construct public com.us.demo.rs.RestApplicationMapper()
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [java.base:]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [java.base:]
    at org.jboss.threads@2.3.1.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) [jboss-threads-2.3.1.Final.jar:2.3.1.Final]
    at org.jboss.threads@2.3.1.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985) [jboss-threads-2.3.1.Final.jar:2.3.1.Final]
    at org.jboss.threads@2.3.1.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487) [jboss-threads-2.3.1.Final.jar:2.3.1.Final]
    at org.jboss.threads@2.3.1.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378) [jboss-threads-2.3.1.Final.jar:2.3.1.Final]
    at java.base/java.lang.Thread.run(Thread.java:834) [java.base:]
    at org.jboss.threads@2.3.1.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485) [jboss-threads-2.3.1.Final.jar:2.3.1.Final]
Caused by: java.lang.RuntimeException: RESTEASY003325: Failed to construct public com.us.demo.rs.RestApplicationMapper()
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:162)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.spi.ResteasyProviderFactory.injectedInstance(ResteasyProviderFactory.java:2702)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$AbstractInterceptorFactory.createInterceptor(JaxrsInterceptorRegistry.java:170)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$OnDemandInterceptorFactory.initialize(JaxrsInterceptorRegistry.java:188)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$OnDemandInterceptorFactory.checkInitialize(JaxrsInterceptorRegistry.java:203)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$OnDemandInterceptorFactory.getInterceptor(JaxrsInterceptorRegistry.java:214)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$AbstractInterceptorFactory.postMatch(JaxrsInterceptorRegistry.java:151)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry.postMatch(JaxrsInterceptorRegistry.java:421)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.interception.ContainerRequestFilterRegistry.postMatch(ContainerRequestFilterRegistry.java:57)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.<init>(ResourceMethodInvoker.java:115)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:345)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.register(ResourceMethodRegistry.java:272)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:223)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:195)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:181)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:158)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:77)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.processApplication(ServletContainerDispatcher.java:178)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:104)
    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
    at io.undertow.servlet//io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:300) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:140) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:579) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:550) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at io.undertow.servlet//io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:592) [undertow-servlet-2.0.0.Final.jar:2.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:97) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78) [wildfly-undertow-12.0.0.Final.jar:12.0.0.Final]
    ... 8 more

Причина: WfaException {Сообщение: не найден EJB, соответствующий полю 'restApiLogger' класса класса com.netapp.wfa.rs.RestApplicationMapper, Причина: null} at creation.wfa-0.5.ear.common-0.5.jar // com.netapp.wfa.common.SessionUtil.injectDependencies (SessionUtil.java:128) на deploy.wfa-0.5.ear.common-0.5.jar //com.netapp.wfa.common.SessionUtil.injectDependencies(SessionUtil.java:70) при развертывании.wfa-0.5.ear.common-0.5.jar // com.netapp.wfa.common.SessionUtil.injectDependencies (SessionUtil.java: 66) at deploy.wfa-0.5.ear.rest-фасад-0.5.war // com.netapp.wfa.rs.RestApplicationMapper. (RestApplicationMapper.java:21) в java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (собственный метод) [java.base:] в java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62) [java.base:] в java.base / jdk.internal.freeDelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45) [java.base:] в java.base / java.lang.reflect.Constructor.newInstance (Constructor.java:490) [java.base:] в org.jboss.resteasy.resteasy-jaxrs //org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:150) ... еще 45

Код, вызывающий исключение

public class SessionUtil {
    public static final String CONTEXT_NAME = "java:global/" + EarUtils.getEarName();
    private List<Object> deployedEjbList; //Note: this is lazy initialized
    private Map<Class, Object> deployedEjbByInterface; //Note: this is (very) lazy initialized

    private static SessionUtil instance = new SessionUtil();

    public static <P> P injectDependencies(P pojo) {
        return injectDependencies(pojo, null);
    }

    public static <P> P injectDependencies(P pojo, EntityManager entityManager) {
        return instance.injectDependencies(pojo, entityManager, null, null);
    }

    protected <P> P injectDependencies(P pojo, EntityManager entityManager, SessionContext sessionContext, UserTransaction userTransaction) {
        if (pojo == null) return null;

        // Loop over the class hierarchy of the pojo
        for (Class clazz = pojo.getClass(); !clazz.equals(Object.class); clazz = clazz.getSuperclass()) {

            // For each class, iterate over its field and look for EJB annotations
            for (Field field : clazz.getDeclaredFields()) {

                // Lookup and inject to @EJB annotated member variables
                if (field.isAnnotationPresent(EJB.class)) {

                    // Get field class and make sure the field is an interface
                    Class<?> fieldClass = getFieldInterface(clazz, field);

                    // Get the EJB to be assigned to this field
                    Object ejb = getEjbForField(fieldClass);
                    if (ejb == null) {
                        throw new WfaException("No EJB was found matching field '" + field.getName() + "' of class " + clazz);
                    }

                    // Assign the EJB to the field
                    assignEjbToField(pojo, clazz, field, ejb);
                }

                // Inject an entityManager to @PersistenceContext annotated member variables
                else if (field.isAnnotationPresent(PersistenceContext.class)) {

                    // Get field class and make sure the field is an interface
                    Class<?> fieldClass = getFieldInterface(clazz, field);

                    if (!EntityManager.class.equals(fieldClass)) {
                        throw new WfaException("Field '" + field.getName() + "' of class " + clazz + " is annotated with PersistenceContext but isn't EntityManager");
                    }

                    // Assign the EntityManager to the field
                    assignEjbToField(pojo, clazz, field, entityManager);
                }

                // Inject a data-source to @Resource annotated member variables with the appropriate class
                else if (field.isAnnotationPresent(Resource.class)) {

                    // Get field class and make sure the field is an interface
                    Class<?> fieldClass = getFieldInterface(clazz, field);

                    // Assign the DataSource to the field
                    if (DataSource.class.equals(fieldClass)) {
                        String dataSourceName = field.getAnnotation(Resource.class).mappedName();
                        assignEjbToField(pojo, clazz, field, getDataSource(dataSourceName));
                    }

                    // Assign the SessionContext to the field
                    else if (SessionContext.class.equals(fieldClass)) {
                        assignEjbToField(pojo, clazz, field, sessionContext);
                    }
                    // Assign the SessionContext to the field
                    else if (UserTransaction.class.equals(fieldClass)) {
                        assignEjbToField(pojo, clazz, field, userTransaction);
                    }
                }
            }
        }

        return pojo;
    }

    public static Map<Class, Object> getDeployedEjbByInterface() {
        if (instance.deployedEjbByInterface == null || instance.deployedEjbByInterface.isEmpty()) {
            instance.initDeployedEjbByInterface();
        }

        return instance.deployedEjbByInterface;
    }

    protected synchronized List<Object> getDeployedEjbList() {
        if (deployedEjbList == null) {
            deployedEjbList = initDeployedEjbList();
        }

        return deployedEjbList;
    }

    private void initDeployedEjbByInterface() {
        // Crate a map from EJB interfaces to EJB instances.
        deployedEjbByInterface = new HashMap<>();
        for (Object ejb : getDeployedEjbList()) {
            for (Class anInterface : ejb.getClass().getInterfaces()) {

                // Register only interfaces annotated as "remote" or "local"
                if (anInterface.getAnnotation(Remote.class) != null || anInterface.getAnnotation(Local.class) != null) {
                    deployedEjbByInterface.put(anInterface, ejb);
                }
            }
        }
    }

    private List<Object> initDeployedEjbList() {
        InitialContext context = null;
        NamingEnumeration<NameClassPair> allWfaEjbNameAndClass = null;
        NamingEnumeration<NameClassPair> internalNamingEnumeration = null;
        try {
            /**
             * Enumerate the names bound in the named context
             */
            context = new InitialContext();

            allWfaEjbNameAndClass = context.list(CONTEXT_NAME);

            /**
             * Iterate the entries in the WFA EAR looking for EJBs with remote/local interfaces
             */
            deployedEjbList = new LinkedList<>();
            while (allWfaEjbNameAndClass.hasMore()) {
                NameClassPair jarNameAndClass = allWfaEjbNameAndClass.next();

                internalNamingEnumeration = context.list(CONTEXT_NAME + "/" + jarNameAndClass.getName());

                while (internalNamingEnumeration.hasMore()) {
                    NameClassPair ejbNameAndClass = internalNamingEnumeration.next();
                    // Skip EJB names with "!" in it as they are duplicate
                    if (ejbNameAndClass.getName().indexOf('!') >= 0) continue;

                    Object ejb = silentLookup(context, CONTEXT_NAME + "/" + jarNameAndClass.getName() + "/" + ejbNameAndClass.getName());
                    if (ejb != null) {
                        deployedEjbList.add(ejb);
                    }
                }
            }

            return deployedEjbList;

        } catch (NamingException e) {
            throw new WfaException("Failed to list EJBs in :" + CONTEXT_NAME, e);
        } finally {

            silentClose(allWfaEjbNameAndClass);
            silentClose(internalNamingEnumeration);
            silentClose(context);
        }
    }

    private Object silentLookup(Context context, String name) {
        try {

            return context.lookup(name);

        } catch (NamingException e) {
            return null;
        }
    }

    private static void silentClose(NamingEnumeration<NameClassPair> namingEnumeration) {
        if (namingEnumeration != null) {
            try {
                namingEnumeration.close();
            } catch (NamingException e) {
                LOGGER.error("Failed to close NamingEnumeration", e);
            }
        }
    }

    protected Object getEjbForField(Class<?> fieldClass) {
        Object obj = getDeployedEjbByInterface().get(fieldClass);

        // If no EJB was found, flush the cache and try again before giving up
        if (obj == null) {
            reset();
            obj = getDeployedEjbByInterface().get(fieldClass);
        }

        return obj;
    }

    public static synchronized void reset() {
        instance.deployedEjbList = null;
        instance.deployedEjbByInterface = null;
    }

    private Class<?> getFieldInterface(Class clazz, Field field) {
        Class<?> fieldClass = field.getType();
        if (!fieldClass.isInterface()) {
            throw new WfaException("Field '" + field.getName() + "' of class " + clazz + " isn't an interface");
        }
        return fieldClass;
    }

    private <P> void assignEjbToField(P pojo, Class clazz, Field field, Object ejb) {
        boolean fieldAccessible = field.isAccessible();
        field.setAccessible(true);
        try {
            field.set(pojo, ejb);
        } catch (Exception e) {
            throw new WfaException("Failed to inject EJB to member '" + field.getName() + "' of class: " + clazz, e);
        } finally {
            field.setAccessible(fieldAccessible);
        }
    }
}

Мое приложение работает наWildfly 12 и Java 8. Теперь я хочу перейти на Java 11, тогда я получил эту проблему.Может кто-нибудь, пожалуйста, помогите мне решить эту проблему?

...