Web Services 无法使字段成为私有静态final jdk.internal.misc.不安全的可访问字段:模块java.base不“打开jdk.internal.misc”

a64a0gku  于 2022-11-15  发布在  Java
关注(0)|答案(1)|浏览(154)

我尝试用Spring Tools读取SOAPWeb服务中的函数,然后用REST API发送结果。

服务接口

package com.example.springbootsoapexample.service;

import org.eclipse.persistence.jaxb.xmlmodel.ObjectFactory;

import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
import jakarta.xml.bind.annotation.XmlSeeAlso;
import jakarta.xml.ws.Action;

@WebService(name = "SOAPDemoSoap", targetNamespace = "http://tempuri.org")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@XmlSeeAlso({ ObjectFactory.class })
public interface IColorService {
    @WebMethod
    @WebResult(partName = "parameters")
    @Action(input = "http://tempuri.org/SOAP.Demo.AddInteger/AddIntegerSoapIn", 
      output = "http://tempuri.org/SOAP.Demo.AddInteger/AddIntegerSoapOut")
    public Long sumar(@WebParam(name = "parameters", partName="Arg1") Long arg0, @WebParam(name = "parameters", partName="Arg2") Long arg1);
}

服务工具

package com.example.springbootsoapexample.service;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;

import jakarta.xml.ws.Service;
import jakarta.xml.ws.WebEndpoint;
import jakarta.xml.ws.WebServiceClient;
import jakarta.xml.ws.WebServiceException;

@WebServiceClient(  name = "SOAPDemo", 
                    targetNamespace = "http://tempuri.org", 
                    wsdlLocation = "https://www.crcind.com:443/csp/samples/SOAP.Demo.cls")
public class ColorServiceImpl extends Service {

    private final static URL COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
    private final static WebServiceException COUNTRYSERVICEIMPLSERVICE_EXCEPTION;
    private final static QName COUNTRYSERVICEIMPLSERVICE_QNAME = 
      new QName("http://tempuri.org", "SOAPDemo");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("https://www.crcind.com:443/csp/samples/SOAP.Demo.cls");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION = url;
        COUNTRYSERVICEIMPLSERVICE_EXCEPTION = e;
    }

    public ColorServiceImpl() {
        super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME);
    }
    
    @WebEndpoint(name = "SOAPDemoSoap")
    public IColorService getColorServiceImpl() {
        return super.getPort(new QName("http://tempuri.org", "SOAPDemoSoap"), 
                IColorService.class);
    }

    private static URL __getWsdlLocation() {
        if (COUNTRYSERVICEIMPLSERVICE_EXCEPTION != null) {
            throw COUNTRYSERVICEIMPLSERVICE_EXCEPTION;
        }
        return COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
    }

}

休息控制器

package com.example.springbootsoapexample.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.springbootsoapexample.service.ColorServiceImpl;
import com.example.springbootsoapexample.service.IColorService;

@RestController
@RequestMapping("/api")
public class ColorRestController {
    ColorServiceImpl colorImpl = new ColorServiceImpl();
    IColorService colorService = colorImpl.getColorServiceImpl();
}

当项目试图运行时,我有这个错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'colorRestController' defined in file [D:\prueba\spring-boot-soap-example\target\classes\com\example\springbootsoapexample\controller\ColorRestController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.springbootsoapexample.controller.ColorRestController]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1306) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1198) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:566) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:526) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:928) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:926) ~[spring-context-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:592) ~[spring-context-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:309) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
    at com.example.springbootsoapexample.SpringBootSoapExampleApplication.main(SpringBootSoapExampleApplication.java:17) ~[classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.springbootsoapexample.controller.ColorRestController]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:219) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1299) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    ... 17 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
    at com.sun.xml.ws.model.WrapperBeanGenerator.createRequestWrapperBean(WrapperBeanGenerator.java:274) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.model.RuntimeModeler.getRequestWrapperClass(RuntimeModeler.java:345) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:771) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:701) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:461) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:290) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:70) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:44) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:28) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:90) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:852) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:869) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:832) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:421) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:390) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:372) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at jakarta.xml.ws.Service.getPort(Service.java:139) ~[jakarta.xml.ws-api-3.0.0.jar:3.0.0]
    at com.example.springbootsoapexample.service.ColorServiceImpl.getColorServiceImpl(ColorServiceImpl.java:43) ~[classes/:na]
    at com.example.springbootsoapexample.controller.ColorRestController.<init>(ColorRestController.java:13) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:206) ~[spring-beans-6.0.0-M4.jar:6.0.0-M4]
    ... 19 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final jdk.internal.misc.Unsafe jdk.internal.misc.Unsafe.theUnsafe accessible: module java.base does not "opens jdk.internal.misc" to unnamed module @740fb309
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) ~[na:na]
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:172) ~[na:na]
    at com.sun.xml.ws.model.Injector$2.run(Injector.java:71) ~[jaxws-rt-3.0.0.jar:3.0.0]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) ~[na:na]
    at com.sun.xml.ws.model.Injector.<clinit>(Injector.java:66) ~[jaxws-rt-3.0.0.jar:3.0.0]
    ... 44 common frames omitted

最后一个原因是服务实现中的函数***getColorServiceImpl()***,但我不知道原因。This is the WS

qcbq4gxm

qcbq4gxm1#

尝试添加JVM参数:--add-opens java.base/jdk.internal.misc=ALL-UNNAMED。这允许对jdk.internal.misc.Unsafe进行反射访问。如果您使用的是Java 16或更低版本,也可以尝试添加--illegal-access=permit来代替--illegal-access=permit

相关问题