。java.lang.NoSuchMethodError:org.json.JSONObject <初始化>(Ljava /郎/对象;)V

Nuñito德拉卡尔萨达:

我有一个基本的SpringBoot 2.1.5.RELEASE应用。使用Spring初始化程序,JPA,嵌入式的Tomcat,Thymeleaf的模板引擎,以及包装与一些RestControllers可执行的JAR文件。

在控制器的1这是身体我送:

{
    "depositHotel": "xxx",
    "destinationHotel": "aaa",
    "depositHotelAmount": "0.2",
    "destinationHotelAmount": "4",
    "destinationAddress": [{
        "address": "asdf",
        "tag": ""
    }],
    "refundAddress": [{
        "address": "pio",
        "tag": ""
    }]
}

所以我创建这个类,以将其作为一个RequestBody:

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"address",
"tag"
})
public class Address {



    public Address() {
        super();
    }

    public Address(String address) {
        super();
        this.address = address;
    }

    @JsonProperty("address")
    private String address;
    @JsonProperty("tag")
    private Object tag;


    @JsonProperty("address")
    public String getAddress() {
    return address;
    }

    @JsonProperty("address")
    public void setAddress(String address) {
    this.address = address;
    }

    @JsonProperty("tag")
    public Object getTag() {
    return tag;
    }

    @JsonProperty("tag")
    public void setTag(Object tag) {
    this.tag = tag;
    }
}

公共类HotelswitchHotelOrderRequestBody {

    public static class Builder {

        private String depositHotel;
        private String destinationHotel;
        private Float depositHotelAmount;
        private Float destinationHotelAmount;
        private Address destinationAddress;
        private Address refundAddress;


        public Builder(String depositHotel, String destinationHotel) {
            this.depositHotel = depositHotel;
            this.destinationHotel = destinationHotel;
        }

        public Builder withDepositHotelAmount (Float depositHotelAmount) {
            this.depositHotelAmount = depositHotelAmount;
            return this;  
        }

        public Builder withDestinationHotelAmount (Float destinationHotelAmount) {
            this.destinationHotelAmount = destinationHotelAmount;
            return this;  
        }

        public Builder toDestinationAddress (Address destinationAddress) {
            this.destinationAddress = destinationAddress;
            return this;  
        }

        public Builder toRefundAddress (Address refundAddress) {
            this.refundAddress = refundAddress;
            return this;  
        }

        public HotelswitchHotelOrderRequestBody build(){

            HotelswitchHotelOrderRequestBody order = new HotelswitchHotelOrderRequestBody(); 
            order.depositHotel = this.depositHotel;
            order.depositHotelAmount = this.depositHotelAmount;
            order.destinationAddress = this.destinationAddress;
            order.destinationHotel = this.destinationHotel;
            order.destinationHotelAmount = this.destinationHotelAmount;
            order.refundAddress = this.refundAddress;

            return order;

        }
    }


    private String depositHotel;
    private String destinationHotel;
    private Float depositHotelAmount;
    private Float destinationHotelAmount;
    private Address destinationAddress;
    private Address refundAddress;


    private HotelswitchHotelOrderRequestBody () {
        //Constructor is now private.
    }


    public String getDepositHotel() {
        return depositHotel;
    }


    public void setDepositHotel(String depositHotel) {
        this.depositHotel = depositHotel;
    }


    public String getDestinationHotel() {
        return destinationHotel;
    }


    public void setDestinationHotel(String destinationHotel) {
        this.destinationHotel = destinationHotel;
    }


    public Float getDepositHotelAmount() {
        return depositHotelAmount;
    }


    public void setDepositHotelAmount(Float depositHotelAmount) {
        this.depositHotelAmount = depositHotelAmount;
    }


    public Float getDestinationHotelAmount() {
        return destinationHotelAmount;
    }


    public void setDestinationHotelAmount(Float destinationHotelAmount) {
        this.destinationHotelAmount = destinationHotelAmount;
    }


    public Address getDestinationAddress() {
        return destinationAddress;
    }


    public void setDestinationAddress(Address destinationAddress) {
        this.destinationAddress = destinationAddress;
    }


    public Address getRefundAddress() {
        return refundAddress;
    }

    public void setRefundAddress(Address refundAddress) {
        this.refundAddress = refundAddress;
    }
}

public test postOrder ( HotelswitchHotelOrderRequestBody order) {



        HttpEntity<String> entity = new HttpEntity<String>(new JSONObject(order).toString(), headers());

        ResponseEntity<OrderResponse> response = new RestTemplate()
                  .exchange(URL, 
                          HttpMethod.POST, entity,  new ParameterizedTypeReference<OrderResponse>() {});

        return response.getBody();

    }

但我有此错误:

java.lang.NoSuchMethodError: org.json.JSONObject.<init>(Ljava/lang/Object;)V
    at io.bonanza.backend.service.Hotelswitch.HotelswitchHotelService.postOrder(HotelswitchHotelService.java:132)
    at io.bonanza.backend.service.Hotelswitch.HotelswitchHotelServiceTests.testPostOrder(HotelswitchHotelServiceTests.java:151)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

pom.xml中:

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>       

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency> 

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
         </dependency>

         <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.googlecode.libphonenumber</groupId>
            <artifactId>libphonenumber</artifactId>
            <version>8.9.0</version>
        </dependency>


        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>

        <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <!-- Spring Security -->

        <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-test -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>





        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
           <!--  <version>4.5.4</version> -->
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>

           <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
       <dependency>
          <groupId>javax.ws.rs</groupId>
          <artifactId>javax.ws.rs-api</artifactId>
          <version>2.1.1</version>
       </dependency>


        <!-- Firebase dependencies -->
       <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>5.4.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-firestore</artifactId>
            <version>0.26.0-beta</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.0</version>
        </dependency>

    </dependencies>
Shubham Kadlag:

它看起来就像你有一个以上的org.json:在classpath JSON依赖。

看一下:

org.springframework.boot:spring-boot-starter-test 取决于

com.jayway.jsonpath:json-pathwhich 又将带来

org.json:json 这可能比版本新/旧的上

io.jsonwebtoken jjwt 0.9.1 被dependend上

你可以尝试从弹簧引导启动测试/ io.jsonwebtoken排除这个传递依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </exclusion>
    </exclusions>
</dependency>

OR / AND

<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt</artifactId>
    <version>0.9.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </exclusion>
    </exclusions>
</dependency>

但是,它可能是有JSON-路径中一些东西,取决于从旧的JSON库,这是在新版本不再东西,谨慎和测试的一切彻底让进行。还有一个机会,别的东西带来org.json:JSON。

要进行验证,请运行mvn dependency:tree和在生产输出搜索org.json:json

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

星火启动。java.lang.NoSuchMethodError:org.yaml.snakeyaml.Yaml <初始化>

爪哇 - 的这种用法的java /郎/的ProcessBuilder <初始化>([Ljava /郎/字符串)。v可以是易受命令注入(声纳)

java.lang.NoSuchMethodError:org.mockito.internal.runners.RunnerFactory.createStrict(Ljava /郎/类;)Lorg /的Mockito /内部/跑步/ InternalRunner;

java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / UTIL /属性

java.lang.NoSuchMethodError:org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava / lang / annotation / Annotation;)Z

错误消息“ java.lang.NoSuchMethodError:客户。<init>(Ljava / lang / String; D)V”

java.lang.NoClassDefFoundError:org / json / JSONObject

java.lang.NoSuchMethodError:android.util.ArrayMap.put(Ljava / lang / Object; Ljava / lang / Object;)Ljava / lang / Object;

解决错误java.lang.NoSuchMethodError:org.codehaus.groovy.ast.ModuleNode.getStarImports()Ljava / util / List;

Selenium Phantomjs驱动程序-java.lang.NoSuchMethodError:org.openqa.selenium.os.CommandLine.find(Ljava / lang / String;)Ljava / lang / String;

java.lang.NoSuchMethodError:org.apache.poi.util.POILogger.log(ILjava / lang / Object; Ljava / lang / Throwable;)V

java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava / util / Map

jboss错误:java.lang.NoSuchMethodError:org.hibernate.internal.CoreMessageLogger.debugf(Ljava / lang / String; I)V

出现错误:...。嵌套异常是java.lang.NoSuchMethodError:org.apache.catalina.Context.addServletMapping(Ljava / lang / Stri

java.lang.NoSuchMethodError:org.apache.poi.ss.usermodel.Workbook.sheetIterator()Ljava / util / Iterator;

java.lang.NoSuchMethodError:org.apache.commons.lang.StringUtils.isBlank(Ljava / lang / String;)Z错误

Hibernate 5 + Glassfish 4.1.1:java.lang.NoSuchMethodError:org.jboss.logging.Logger.debugf(Ljava / lang / String; I)V

Spring-java.lang.NoSuchMethodError:org.springframework.web.accept.ContentNegotiationManager.getStrategies()Ljava / util / List ;?

java.lang.NoSuchMethodError:org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter。<init>(Ljava / lang / reflect / Method;)V

java.lang.NoSuchMethodError:org.openqa.selenium.os.CommandLine.find(Ljava / lang / String;)Ljava / lang / String; 在将PhantomJS 2.1.1与Selenium一起使用时

Databricks错误java.lang.NoSuchMethodError:scala.Predef $ .refArrayOps([Ljava / lang / Object;)[Ljava / lang / Object;

java.lang.NoSuchMethodError:org.springframework.util.StringUtils.matchesCharacter(Ljava / lang / String; C)Z

线程“ AWT-EventQueue-0”中的异常java.lang.NoSuchMethodError:org.apache.xmlbeans.XmlOptions.put(Ljava / lang / Object;)V

VM初始化期间发生错误:java.lang.UnsatisfiedLinkError:java.lang.Class.desiredAssertionStatus0(Ljava / lang / Class;)

java.lang.NoSuchMethodError:javax.persistence.EntityManager.setProperty(Ljava / lang / String; Ljava / lang / Ob ject;)V

java.lang.NoSuchMethodError的原因:com.sun.jna.Native.register(Ljava / lang / String;)V

java.lang.NoSuchMethodError:org.jboss.logging.Logger.debugf(Ljava / lang / String; I)V WebLogic部署

java.lang.NoSuchMethodError:org.jboss.logging.Logger.debugf(Ljava / lang / String; I)V从12.1.3迁移到12.2时发生异常

Hibernate中的@Convert无法与Spring 4,java.lang.NoSuchMethodError一起使用:org.hibernate.cfg.Configuration.addAttributeConverter(Ljava / lang / Class;)V