java: cannot access org.springframework.boot.SpringApplication
bad class file: /C:/Users/xyz/.m2/repository/org/springframework/boot/spring-boot/3.0.0-SNAPSHOT/spring-boot-3.0.0-20220910.145857-773.jar!/org/springframework/boot/SpringApplication.class
class file has wrong version 61.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
Run Code Online (Sandbox Code Playgroud) application.propertiesSpring 应用程序中的以下设置有何作用?
server.error.include-binding-errors=on-param
Run Code Online (Sandbox Code Playgroud)
我在文档中找不到它。
和always值never非常不言自明,但我不明白on-param。
我想@Delegate在我的代码中使用 lombok 的注释。请检查下面的代码片段,它会抛出一个错误:getAge()已定义:
public interface I {
String getName();
int getAge();
}
@Data
public class Vo {
private String name;
private long age;
}
@AllArgsConstructor
public class Adapter implements I {
@Delegate(types = I.class)
private Vo vo;
//I want to use my own code here,Because vo.getAge() returns a long,But I.getAge() expects a int
public int getAge(){
return (int) vo.getAge();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试支持定期清除的哈希图上的并发性。我有一个缓存,可以存储一段时间的数据。每 5 分钟后,此缓存中的数据将发送到服务器。一旦我刷新,我想清除缓存。问题是当我刷新时,当我使用现有密钥执行此操作时,数据可能会写入此映射。我将如何使这个进程线程安全?
data class A(val a: AtomicLong, val b: AtomicLong) {
fun changeA() {
a.incrementAndGet()
}
}
class Flusher {
private val cache: Map<String, A> = ConcurrentHashMap()
private val lock = Any()
fun retrieveA(key: String){
synchronized(lock) {
return cache.getOrPut(key) { A(key, 1) }
}
}
fun flush() {
synchronized(lock) {
// send data to network request
cache.clear()
}
}
}
// Existence of multiple classes like CacheChanger
class CacheChanger{
fun incrementData(){
flusher.retrieveA("x").changeA()
}
}
Run Code Online (Sandbox Code Playgroud)
我担心上面的缓存没有正确同步。有没有更好/正确的方法来锁定这个缓存,这样我就不会丢失数据?我应该创建缓存的深层副本并清除它吗?
既然上面的数据可能被另一个更改器更改,那会不会导致问题?
java concurrency java.util.concurrent thread-synchronization kotlin
我正在学习如何使用 JUnit 5 在 Kotlin 中编写测试。当我编写 Java 时@Nested,我喜欢使用 、@ParametrizedTest等功能。@MethodSource但是当我切换到 Kotlin 时,我遇到了一个问题:
我想出了如何使用
@Nested通过在运行 gradle 测试时未找到嵌套 Kotlin 类中引用此JUnit 测试@ParametrizedTest并@MethodSource参考适用于 Kotlin 开发人员的 JUnit 5 - 第 4.2 节但当我把这些放在一起时,我得到了
这里不允许使用伴随对象。
在内部类里面。
测试重现错误
internal class SolutionTest {
@Nested
inner class NestedTest {
@ParameterizedTest
@MethodSource("testCases")
fun given_input_should_return_expected(input: Int, expected: Int) {
// assert
}
// error in below line
companion object {
@JvmStatic
fun testCases(): List<Arguments> {
return emptyList()
}
} …Run Code Online (Sandbox Code Playgroud) 我已经更新了我的项目的库和依赖项,包括:
该应用程序可以成功构建,我尝试将其部署到运行OpenJDK 17的Payara Server 6.2022.2。但是,不断抛出以下错误,并且Spring无法启动。
我已经确认Springboot是最新版本并且支持Java 17环境。是否缺少任何依赖项?
我的 pom.xml :
Run Code Online (Sandbox Code Playgroud)<modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.1</version> <relativePath/> </parent> <version>1.0</version> <packaging>war</packaging> <properties> <java.version>17</java.version> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <artifactId>tomcat-embed-logging-juli</artifactId> <groupId>org.apache.tomcat.embed</groupId> </exclusion> <exclusion> <artifactId>tomcat-embed-websocket</artifactId> <groupId>org.apache.tomcat.embed</groupId> </exclusion> <exclusion> <artifactId>tomcat-embed-el</artifactId> <groupId>org.apache.tomcat.embed</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-loader</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> …
我有一个下载文件的休息方法。但是,在文件完全复制到输出流之前,似乎不会在 Web 客户端上开始下载,这对于大文件可能需要一段时间。
@GetMapping(value = "download-single-report")
public void downloadSingleReport(HttpServletResponse response) {
File dlFile = new File("some_path");
try {
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename="+ dlFile.getName());
InputStream inputStream = new FileInputStream(dlFile);
IOUtils.copy(inputStream, response.getOutputStream());
response.flushBuffer();
} catch (FileNotFoundException e) {
// error
} catch (IOException e) {
// error
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法“流式传输”文件,以便在我开始写入输出流时立即开始下载?
我还有一个类似的方法,它将多个文件放入一个 zip 文件中,将每个 zip 条目添加到 zip 流中,并且下载也仅在创建 zip 文件后才开始:
ZipEntry zipEntry = new ZipEntry(entryName);
zipOutStream.putNextEntry(zipEntry);
IOUtils.copy(fileStream, zipOutStream);
Run Code Online (Sandbox Code Playgroud) 关于mapStruct的问题。我有这样的情况:我从基本实体扩展类,但不确定如何映射它。这是我的案例。
基础实体:
public class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
基数为:
public class BaseDto {
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
用户实体:
public class User extends BaseEntity {
private String name;
private String lastName;
private String username;
private String password;
private String profilePicturePath;
}
Run Code Online (Sandbox Code Playgroud)
用户D至:
public class UserDto extends BaseDto {
private String name;
private String lastName;
private String username;
private String password;
private String profilePicturePath;
}
Run Code Online (Sandbox Code Playgroud)
映射器是这样的:
@Mapper(uses = {BaseMapper.class})
public interface UserMapper { …Run Code Online (Sandbox Code Playgroud) 我对模块化 Java 的兴趣已经几个月了,包括 Spring 和相关的生态系统内容。最令人沮丧的经历之一是调试名称不明确的模块问题
这是我遇到的最后一个此类错误:
java.lang.IllegalAccessError: superclass access check failed: class com.oracle.truffle.polyglot.PolyglotImpl (in unnamed module @0x58a90037) cannot access class org.graalvm.polyglot.impl.AbstractPolyglotImpl (in module org.graalvm.sdk) because module org.graalvm.sdk does not export org.graalvm.polyglot.impl to unnamed module @0x58a90037
@0x58a90037问题就在这里。
根据我要做的事情,我会随机尝试spring.beans,spring.context等等javax.validation......并向世界开放我的模块,这在某种程度上消除了首先封装它们的价值。
对于这个具体案例,我尝试过虽然进展并不顺利,但还是requires org.graalvm.sdk;requires org.graalvm.js;做到了。
通过随机尝试进行调试似乎并不是解决这些问题的明智方法。所以我想知道你们是怎么做到的。
谢谢你!
如何获取记录,计数总和应该在限制内。在下面的示例中,Records对象包含 recordId 和计数,我想根据计数的总和应该小于或等于我的限制条件来获取记录数据。
public class Records {
private int recordID;
private int count;
public Records(int recordID, int count) {
this.recordID = recordID;
this.count = count;
}
public int getRecordID() {
return recordID;
}
public void setRecordID(int recordID) {
this.recordID = recordID;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
public static void main(String[] args) {
final List<Records> recordList = new ArrayList<>();
recordList.add(new Records(100, 10));
recordList.add(new Records(501, 20));
recordList.add(new …Run Code Online (Sandbox Code Playgroud) java ×7
spring ×3
kotlin ×2
spring-boot ×2
annotations ×1
boot ×1
concurrency ×1
java-17 ×1
java-8 ×1
java-module ×1
java-platform-module-system ×1
java-stream ×1
junit5 ×1
lombok ×1
mapstruct ×1
maven ×1
payara ×1
spring-mvc ×1
sprint ×1