我已经搜索了高低,但仍然无法找到这个非常烦人的问题的简单答案,
我遵循了这个很棒的指南: 带有多服务应用程序的 JWT 一切都很好,但在指南的最后,我们建议创建一个 config-service(module) ,我已经完成了。
问题是我无法覆盖 JwtConfig 类的默认配置
项目结构如下:
-config-service
| JwtConfig.java
\
| resources
\
| jwtConfig.properties
-other-service (add dependency in the pom file of the config-service)
|
someOtherclass.java (import the JwtConfig class & using @Bean to initialize )
Run Code Online (Sandbox Code Playgroud)
JwtConfig 类:
/*all the imports*/
@PropertySource(value = "classpath:jwtConfig.properties")
public class JwtConfig {
@Value("${security.jwt.uri:/auth/**}")
private String Uri;
@Value("${security.jwt.header:Authorization}")
private String header;
@Value("${security.jwt.prefix:Bearer }")
private String prefix;
@Value("${security.jwt.expiration:#{24*60*60}}")
private int expiration;
@Value("${security.jwt.secret:JwtSecretKey}")
private String secret;
//getters
Run Code Online (Sandbox Code Playgroud)
someOtherclass.java:
/*imports*/
@Configuration
@EnableWebSecurity …Run Code Online (Sandbox Code Playgroud) maven multi-module spring-boot application.properties java-11
在 Java 11 中,JAX-WS 已从 JDK 中删除。它可以防止wsimport在引擎盖下使用 Maven 插件轻松生成 JAX-WS 类。我正在为 Maven 插件使用以下配置org.codehaus.mojo:jaxws-maven-plugin。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<extension>true</extension>
<packageName>tech.myproject.service</packageName>
<wsdlFiles>
<wsdlFile>${basedir}/src/main/resources/wsdl/service.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/wsdl/service.wsdl</wsdlLocation>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来安装 wsimport 或使用另一个插件捆绑特定架构的 wsimport 来继续生成 WSDL 类?
我试图每隔几分钟不断地向 REST API 发送 GET 和 POST 请求。问题是,在恰好 1000 个请求之后,我收到了一个GOAWAY帧(和一个IOException):
GOAWAY 帧(类型=0x7)用于启动连接关闭或发出严重错误情况的信号。
HTTP/2 规范
我做了一些研究,发现 1000 个请求不仅是nginx 的默认最大值,Cloudfront(相关的 Chromium 问题)和 Discord 也表现出相同的行为。
我尝试使用具有默认 HTTP/2 配置的本地 nginx 服务器重现此问题:
服务器 {
听 443 http2 ssl;
http2_max_requests 1000;
...
}
var client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.build();
for (var i = 0; i < 1100; i++) {
var url = URI.create(String.format("https://localhost/images/test%d.jpg", i));
var request = HttpRequest.newBuilder().uri(url).build();
client.send(request, HttpResponse.BodyHandlers.discarding());
System.out.printf("Image %d processed%n", i);
}
Run Code Online (Sandbox Code Playgroud)
在大约 1000 个请求之后,我收到了 …
我目前正在将一个项目迁移到 JDK 11 并使用 Maven 进行编译。但是,Maven 在单个方法引用上出现了问题(它在其他地方没有问题)。有问题的方法如下所示:
public class MyThing {
boolean something = true;
// ...
public boolean isSomething() {
return something;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
对上述方法的调用或多或少是这样的:
return methodThatGetsOptionalDefinition(aString) // Optional<Definition>
.map(definition -> defenition.getMyThing(anotherString)) // Optional<MyThing>
.map(MyThing::isSomething) // Optional<Boolean>
.orElse(true);
Run Code Online (Sandbox Code Playgroud)
编译这个,Maven 会抛出以下消息:
> mvn clean install -Pdist-snapshot -DskipTests
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project XXXXX: Compilation failure
[ERROR] /D:/XXXXX.java:[63,38] incompatible types: invalid method reference
[ERROR] method isSomething in class XXXXX.MyThing cannot be applied to given types …Run Code Online (Sandbox Code Playgroud) 我正在使用 Android 数据绑定,虽然事情很简单,但效果很好。然而,一旦我添加了一个BindingAdapter注释,我的项目就停止在 Android Studio 中构建并出现错误Execution failed for task ':app:compileSaferesourceDebugJavaWithJavac',但它没有给我更多细节。gradlew build在命令行上运行显示实际错误是java.lang.ClassNotFoundException: javax.xml.bind.JAXBException. 这是有道理的,因为这台开发机器只安装了 Java 11,没有安装 Java 8。
我找到了这个答案,它说要向 gradle 添加以下依赖项:
implementation "javax.xml.bind:jaxb-api:2.2.11"
implementation "com.sun.xml.bind:jaxb-core:2.2.11"
implementation "com.sun.xml.bind:jaxb-impl:2.2.11"
implementation "javax.activation:activation:1.1.1"
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道在哪里添加它们。将它们作为implementation依赖项添加到app/build.gradle不起作用,因为 JAXB 是构建工具的依赖项,而不是我的应用程序本身的依赖项。
我也尝试添加它们buildscript.dependencies,但这也不起作用:
buildscript {
repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "javax.xml.bind:jaxb-api:2.3.1"
classpath "com.sun.xml.bind:jaxb-core:2.3.0"
classpath "com.sun.xml.bind:jaxb-impl:2.3.1"
classpath "javax.activation:activation:1.1.1"
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将它们添加到buildscript.dependencies项目根build.gradle文件中,但这也无济于事:
buildscript {
repositories { …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个 Android 应用程序,其中包含一些在 java 11 中编译的依赖项。
我已经在 build.gradle 中进行了配置:
android {
compileOptions {
sourceCompatibility = 1.11
targetCompatibility = 1.11
}
...
}
Run Code Online (Sandbox Code Playgroud)
我已经使用 java 11 sdk 配置了我的项目结构。
我正在使用这个版本的 android 工具构建插件:
classpath 'com.android.tools.build:gradle:3.5.3'
Run Code Online (Sandbox Code Playgroud)
这个版本的 gradle :
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Run Code Online (Sandbox Code Playgroud)
我还指出了 Gradle JVM 的 java 11。
但是当我编译应用程序时,我总是收到此错误:
Execution failed for task ':app:compileDevJavaWithJavac'.
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.
Run Code Online (Sandbox Code Playgroud)
我不懂为什么。
我检查了我的 JAVA_HOME 和 java -version,它们都指向 11。
有人知道发生了什么事吗?
谢谢
我正在尝试使用 maven 和 lombok 的 @Slf4j Logger 构建 Java 11 项目,但 maven 无法识别这些log变量。IntelliJ 确实做到了,并且能够构建该项目。
错误是
[ERROR]: cannot find symbol variable log
Run Code Online (Sandbox Code Playgroud)
项目和模块 SDK 都是 Java 11。Lombok 版本是 1.18.2:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的 Maven 编译器设置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过:
maven-compiler-plugin注释处理器列表这个问题不是java.lang.NoClassDefFoundError: sun/misc/BASE64Encoder的重复。
我正在尝试更新我的应用程序中的 Java 版本(到 11),并且我的应用程序中的一个库使用sun.misc.BASE64Encoder类,所以我不可避免地会遇到此异常:
Caused by: java.lang.ClassNotFoundException: sun.misc.BASE64Encoder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Run Code Online (Sandbox Code Playgroud)
现在,解决的方法是使用java.util.Base64apache commons,正如其他答案所建议的那样。然而,问题是,这个库属于第三方,我没有它的源代码。似乎没有一个新版本不使用这些类。因此,为了解决这个问题,我执行了以下操作:
sun.miscBASE64Encoder和类CharacterEncoder但现在,我收到一个编译错误,说The package sun.misc conflicts with a package accessible from another module: jdk.unsupported.
有什么办法可以解决这个错误吗?如果没有,我可以添加一个jar包含这些类的依赖项吗?我只是想确保这些类在运行时可用于第三方库(通过我自己的源代码或通过捆绑这些类的 jar)。
从 Java 8 迁移到 Java 11。
将 cxf-codegen-plugin 从版本 3.2.0 更新到 3.3.6。
插件仍然使用 javax.jws.* 中的包(而不是 jakarta.jws.* 中的包)从 wsdl 文件生成 Java 存根:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
* This class was generated by Apache CXF 3.3.6
* 2020-08-12T19:22:40.406+02:00
* Generated source version: 3.3.6
*
*/
Run Code Online (Sandbox Code Playgroud)
我是否误认为 javax.jws 已弃用,应该更改为 jakarta.jws?
如何使用所需的包完成代码生成?
有时我需要为Postgresql安装一个端口,我在容器中运行该端口进行测试。但测试容器开发者命令Testcontainers删除了这个功能。但在某个地方有一个解决方案,通过设置,但我找不到它。谁有关于如何做到这一点的任何想法或信息?
public class ContainerConfig {
private static final PostgreSQLContainer postgresSQLContainer;
static {
DockerImageName postgres = DockerImageName.parse("postgres:13.1");
postgresSQLContainer = (PostgreSQLContainer) new PostgreSQLContainer(postgres)
.withDatabaseName("test")
.withUsername("root")
.withPassword("root")
.withReuse(true);
postgresSQLContainer.start();
}
@SuppressWarnings("rawtypes")
private static PostgreSQLContainer getPostgresSQLContainer() {
return postgresSQLContainer;
}
@SuppressWarnings("unused")
@DynamicPropertySource
public static void registerPgProperties(DynamicPropertyRegistry propertyRegistry) {
propertyRegistry.add("integration-tests-db", getPostgresSQLContainer()::getDatabaseName);
propertyRegistry.add("spring.datasource.username", getPostgresSQLContainer()::getUsername);
propertyRegistry.add("spring.datasource.password", getPostgresSQLContainer()::getPassword);
propertyRegistry.add("spring.datasource.url", getPostgresSQLContainer()::getJdbcUrl);
}
}
Run Code Online (Sandbox Code Playgroud) java-11 ×10
java ×7
maven ×4
android ×2
gradle ×2
spring-boot ×2
base64 ×1
deprecated ×1
http2 ×1
java-8 ×1
jax-ws ×1
jaxb ×1
lambda ×1
lombok ×1
multi-module ×1
postgresql ×1
wsdl ×1
wsdl2java ×1