java - 在 Windows 上运行良好的 Java 代码在 Ubuntu 上无法运行
问题描述
我有一些 Java(SpringBoot 应用程序)代码,我在两台机器上以 1:1 的比例复制:一台使用 Windows,第二台使用 Ubuntu 操作系统。
代码包括: 一个DTO
喜欢:
import java.math.BigDecimal;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModelProperty;
import lombok.Value;
@Value
public class Simple {
@ApiModelProperty(example = "12.00")
@NotNull
@Min(value = 1)
@Max(value = 1)
private final BigDecimal test;
}
控制器:
@RestController
@Slf4j
@RequestMapping("/test/")
@AllArgsConstructor
class SimulatorController {
@PostMapping(value = "test", consumes = MediaType.APPLICATION_JSON_VALUE)
void test(
@Valid
@NotNull
@RequestBody Simple simple
) {
log.info("Got request [{}]", simple);
}
主要的pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.bnp.retail.okd.ho</groupId>
<artifactId>backend-spring-template-parent</artifactId>
<version>0.0.0</version>
<packaging>pom</packaging>
<name>app</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<springfox.version>2.9.2</springfox.version>
</properties>
<modules>
<module>app</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>a</groupId>
<artifactId>backend-spring-template-app</artifactId>
<version>0.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>a.AppConfig</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<skipITs>false</skipITs>
</configuration>
</plugin>
</plugins>
</build>
</project>
App
起居室:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>pl.bnp.retail.okd.ho</groupId>
<artifactId>backend-spring-template-parent</artifactId>
<version>0.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.9.2</version>
</dependency>
</dependencies>
</project>
现在奇怪的是,Ubuntu
我大摇大摆地出错了:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造实例
pl.bnp.retail.okd.ho.simulator.model.SimpleSimulatorInputWithInstallmentMonthlyAmount
(没有创建者,如默认构造,存在):无法从 [来源:(PushbackInputStream)的对象值(没有基于委托或基于属性的创建者)反序列化;行:2,列:3]
但Windows
它工作正常(它打印出很好的ToString()
内容)
我想知道为什么?
.m2
我什至从目录中删除了所有存储库,Windows
然后再次构建项目,但它仍然运行良好。
我能看到的唯一区别是在 Windows 上我有 Java 11.0.2,但在 Ubuntu 上它是 Java 11.0.4。
java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
编辑:
添加附加lombok.config
文件Ubuntu
lombok.anyConstructor.addConstructorProperties=true
最终@AllArgsConstructor
,即使这个注释消失了,现在也很难在 Ubuntu 上打破它。
使代码运行良好,但我想知道为什么?为什么在这种情况下操作系统之间存在差异?
解决方案
推荐阅读
- ios - 为什么通过 Multipeer Connectivity 发送的字符串在接收端会出现乱码?
- java - 在 Linux 上运行时,Cacerts 文件未应用于 TrustStore
- python-3.x - 熊猫在所有行上显示组总和
- scala - 阿帕奇星火;图 X ; 如何结合两个边缘RDD
- machine-learning - 在强化学习中将离散动作转换为连续动作
- dictionary - Elixir 将键值对从 Map 连接到现有字符串(FDF 文件生成)
- java - 如何在允许选择更改之前验证数据?
- javascript - 离子刷新器与隐藏显示动画AngularJS冲突
- java - JBoss AS 5.1 通过 TLS 与 Websphere MQ 集成
- c# - 错误:验证时发生错误。HRESULT = '80070057'