dha*_*n10 24 java spring maven
目前我正在关注此 youtube 上的课程视频:https://www.youtube.com/watch?v
=BHoiNd64w0c&list=PLQag1tT77Ben3dupVMgYtoi_PVVQVRdD6&index=13 一切正常,我通过单击 Eclipse 中的播放按钮来运行我的项目,导师的操作有点不同,因为他使用sts工具。right click > run as > maven install
但是当尝试基于这个问题How to fix "Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass?时会发生错误,我已经使用了较新的 spring 版本。这是我的 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.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>java-login-security</groupId>
<artifactId>login-system</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>login-system</name>
<description>login system</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.70</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
这里有更多错误日志:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.7)
2023-01-14 12:19:00.834 INFO 2373 --- [ main] j.l.LoginSystemApplicationTests : Starting LoginSystemApplicationTests using Java 17.0.4.1 on dna with PID 2373 (started by dna in /media/dna/data/koding/java/login-system)
2023-01-14 12:19:00.835 INFO 2373 --- [ main] j.l.LoginSystemApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-01-14 12:19:01.333 INFO 2373 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-01-14 12:19:01.380 INFO 2373 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 41 ms. Found 1 JPA repository interfaces.
2023-01-14 12:19:01.530 ERROR 2373 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @78dd667e
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:598) ~[spring-core-5.3.24.jar:5.3.24]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.3.24.jar:5.3.24]
// ...more error log here...
Run Code Online (Sandbox Code Playgroud)
我的java版本:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.7)
2023-01-14 12:19:00.834 INFO 2373 --- [ main] j.l.LoginSystemApplicationTests : Starting LoginSystemApplicationTests using Java 17.0.4.1 on dna with PID 2373 (started by dna in /media/dna/data/koding/java/login-system)
2023-01-14 12:19:00.835 INFO 2373 --- [ main] j.l.LoginSystemApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-01-14 12:19:01.333 INFO 2373 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-01-14 12:19:01.380 INFO 2373 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 41 ms. Found 1 JPA repository interfaces.
2023-01-14 12:19:01.530 ERROR 2373 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @78dd667e
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:598) ~[spring-core-5.3.24.jar:5.3.24]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.3.24.jar:5.3.24]
// ...more error log here...
Run Code Online (Sandbox Code Playgroud)
[更新]你可以在这里检查我的项目: https ://github.com/dhanyn10/java/tree/main/login-system
小智 36
我遇到过同样的问题。这是因为我的项目是用 Java 8 编写的,但我尝试在 Java 17 中启动。我刚刚将 IntelliJ 中的 Build&Run 配置从 SDK 17 更改为正确的 Java 版本 8 并且它有效。也许您使用了另一个 Java 版本在 IntelliJ 中构建项目。
这是配置屏幕截图。
| 归档时间: |
|
| 查看次数: |
62196 次 |
| 最近记录: |