我正在构建一个springbootweb应用程序,它使用mongodb作为数据存储。我使用mongodburi直接与实时集群(不是本地集群)通信。我正在使用Java11(采用OpenJDK11.0.5)。
在应用程序启动时,由于tls/ssl错误,我的应用程序无法与mongodb群集通信:
com.mongodb.MongoSocketWriteException: Exception sending message
at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:551) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:433) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:273) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:257) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:105) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:62) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:129) ~[mongodb-driver-core-3.11.2.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.11.2.jar:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131) ~[na:na]
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:307) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263) ~[na:na
根据mongodb驱动程序网站上的消息来源,他们解释说这是Java11的一个已知问题。我认为问题是openjdk提交的这个bug,它注意到了tls1.3的ssl连接实现的一个问题。这为我提供了两种选择:
升级到已修复此问题的java版本。
设置 jdk.tls.client.protocols
系统属性值 TLSv1.2
.
我已经能够验证在升级到Java15时这个问题没有得到解决;错误保持不变。在清理和重新运行应用程序之前,我仔细检查了是否确实在使用Java15 mvn spring-boot:run
.
这让我有了第二个选择,这就引出了我的问题:
使用maven构建时,如何正确设置jdk.tls.client.protocols系统属性?
我试过用 mvn spring-boot:run -Djdk.tls.client.protocols=TLSv1.2
但这仍然会产生与以前相同的错误。
我已经提供了我的 pom.xml
在下面;我在项目中没有与mongodb自动设置相关的文件/代码,您可以在这里完整地检查这些文件/代码。
为了澄清,我请 localhost
生成配置文件。 pom.xml
:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>edu.ucsb</groupId>
<artifactId>mapache-search</artifactId>
<version>0.1.0</version>
<name>Mapache Search</name>
<description>Mapache Search (CMPSC 156 class project)</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.10.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth.boot/spring-security-oauth2-autoconfigure -->
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version>
</dependency>
<!-- jpa, crud repository -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- add mongodb repositories -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.codebox/javabean-tester -->
<dependency>
<groupId>net.codebox</groupId>
<artifactId>javabean-tester</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>javascript</workingDirectory>
<installDirectory>target</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v12.12.0</nodeVersion>
<npmVersion>6.14.3</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>ci</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<target>
<copy todir="${project.build.directory}/classes/public">
<fileset dir="${project.basedir}/javascript/build" />
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<!-- Fix the error
Exit code: 1 - javadoc: error - The code being documented uses modules
but the packages defined in http://docs.oracle.com/javase/8/docs/api/
are in the unnamed module. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>11</source>
</configuration>
<version>3.1.0</version>
</plugin>
<!-- Make jar file executable -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<!-- full package name of class with the main you want to run -->
<mainClass>edu.ucsb.mapache.DemoApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Test case coverage report -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.8.2</version>
</plugin>
</plugins>
</build>
<!-- (28) <profiles/> -->
<profiles>
<profile>
<id>localhost</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>src/main/config/localhost</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>.</directory>
<include>secrets-localhost.properties</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<environment-properties />
</properties>
</profile>
<profile>
<id>test</id>
<activation>
<property>
<name>env.TEST_PROPERTIES</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<environment-properties>${env.TEST_PROPERTIES}</environment-properties>
</properties>
</profile>
<profile>
<id>heroku</id>
<activation>
<property>
<name>env.HEROKU_PROPERTIES</name>
</property>
</activation>
<build>
<resources>
<resource>
<directory>src/main/config/heroku</directory>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<properties>
<environment-properties>${env.HEROKU_PROPERTIES}</environment-properties>
</properties>
</profile>
</profiles>
</project>
我还包括了 mvn dependency:tree
下图:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< edu.ucsb:mapache-search >-----------------------
[INFO] Building Mapache Search 0.1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ mapache-search ---
[INFO] edu.ucsb:mapache-search:jar:0.1.0
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:2.2.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.2.5.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.5.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.12.1:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.12.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.25:runtime
[INFO] | +- org.springframework:spring-aop:jar:5.2.4.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.2.4.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:5.2.2.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:5.2.4.RELEASE:compile
[INFO] | \- org.springframework.security:spring-security-web:jar:5.2.2.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.2.5.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.2:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.2:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.10.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.5.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.31:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.31:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.31:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.5.RELEASE:compile
[INFO] | | +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | | \- org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:compile
[INFO] | +- org.springframework:spring-web:jar:5.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.2.5.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:2.2.5.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.2.5.RELEASE:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] | | +- net.minidev:json-smart:jar:2.3:test
[INFO] | | | \- net.minidev:accessors-smart:jar:1.2:test
[INFO] | | | \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter:jar:5.5.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-api:jar:5.5.2:test
[INFO] | | | +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] | | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | | \- org.junit.platform:junit-platform-commons:jar:1.5.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-params:jar:5.5.2:test
[INFO] | | \- org.junit.jupiter:junit-jupiter-engine:jar:5.5.2:test
[INFO] | | \- org.junit.platform:junit-platform-engine:jar:1.5.2:test
[INFO] | +- org.mockito:mockito-junit-jupiter:jar:3.1.0:test
[INFO] | +- org.assertj:assertj-core:jar:3.13.2:test
[INFO] | +- org.hamcrest:hamcrest:jar:2.1:compile
[INFO] | +- org.mockito:mockito-core:jar:3.1.0:test
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.10.8:compile
[INFO] | | +- net.bytebuddy:byte-buddy-agent:jar:1.10.8:test
[INFO] | | \- org.objenesis:objenesis:jar:2.6:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] | +- org.springframework:spring-core:jar:5.2.4.RELEASE:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.2.4.RELEASE:compile
[INFO] | +- org.springframework:spring-test:jar:5.2.4.RELEASE:test
[INFO] | \- org.xmlunit:xmlunit-core:jar:2.6.3:test
[INFO] +- org.springframework.security:spring-security-test:jar:5.2.2.RELEASE:test
[INFO] | \- org.springframework.security:spring-security-core:jar:5.2.2.RELEASE:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.11:compile
[INFO] +- org.json:json:jar:20190722:compile
[INFO] +- com.auth0:java-jwt:jar:3.10.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.2:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.10.2:compile
[INFO] | \- commons-codec:commons-codec:jar:1.13:compile
[INFO] +- org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:jar:2.2.5.RELEASE:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.2:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.2.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.5.RELEASE:compile
[INFO] | +- org.springframework.security.oauth:spring-security-oauth2:jar:2.3.8.RELEASE:compile
[INFO] | | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | \- org.springframework.security:spring-security-jwt:jar:1.0.11.RELEASE:compile
[INFO] | \- org.bouncycastle:bcpkix-jdk15on:jar:1.64:compile
[INFO] | \- org.bouncycastle:bcprov-jdk15on:jar:1.64:compile
[INFO] +- org.glassfish.jaxb:jaxb-runtime:jar:2.4.0-b180830.0438:compile
[INFO] | +- org.glassfish.jaxb:txw2:jar:2.3.2:compile
[INFO] | +- com.sun.istack:istack-commons-runtime:jar:3.0.7:compile
[INFO] | +- org.jvnet.staxex:stax-ex:jar:1.8:compile
[INFO] | +- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.15:compile
[INFO] | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.2.5.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:2.2.5.RELEASE:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.9.5:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.2.5.RELEASE:compile
[INFO] | | +- com.zaxxer:HikariCP:jar:3.4.2:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:5.2.4.RELEASE:compile
[INFO] | +- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] | +- jakarta.persistence:jakarta.persistence-api:jar:2.2.3:compile
[INFO] | +- jakarta.transaction:jakarta.transaction-api:jar:1.3.3:compile
[INFO] | +- org.hibernate:hibernate-core:jar:5.4.12.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] | | +- org.javassist:javassist:jar:3.24.0-GA:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | +- org.jboss:jandex:jar:2.1.1.Final:compile
[INFO] | | +- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] | | +- org.dom4j:dom4j:jar:2.1.1:compile
[INFO] | | \- org.hibernate.common:hibernate-commons-annotations:jar:5.1.0.Final:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:2.2.5.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:2.2.5.RELEASE:compile
[INFO] | | +- org.springframework:spring-orm:jar:5.2.4.RELEASE:compile
[INFO] | | \- org.springframework:spring-tx:jar:5.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-aspects:jar:5.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-mongodb:jar:2.2.5.RELEASE:compile
[INFO] | +- org.mongodb:mongodb-driver:jar:3.11.2:compile
[INFO] | | +- org.mongodb:bson:jar:3.11.2:compile
[INFO] | | \- org.mongodb:mongodb-driver-core:jar:3.11.2:compile
[INFO] | \- org.springframework.data:spring-data-mongodb:jar:2.2.5.RELEASE:compile
[INFO] +- net.codebox:javabean-tester:jar:1.0.0:compile
[INFO] | \- junit:junit:jar:4.12:compile
[INFO] | \- org.hamcrest:hamcrest-core:jar:2.1:compile
[INFO] \- com.h2database:h2:jar:1.4.200:runtime
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.022 s
[INFO] Finished at: 2020-12-10T12:28:18-08:00
[INFO] ------------------------------------------------------------------------
1条答案
按热度按时间ldxq2e6h1#
下面是如何正确传递该变量(对于SpringBoot2.x.x):
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Djdk.tls.client.protocols=TLSv1.2"