maven UnsupportedClassVersionError:未启用预览功能< class>(类文件版本60.65535)

nszi6y05  于 2023-10-17  发布在  Maven
关注(0)|答案(1)|浏览(95)
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Java version: 16.0.1, vendor: Oracle Corporation
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

我通过mvn spring-boot:run启动Spring应用程序。现在,每当我更改类路径上的文件时,服务器重启失败:
输出

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.2)

2021-07-22 15:48:03.648  INFO 9756 --- [  restartedMain] de.xehpuk.foo.Application                : Starting Application using Java 16.0.1 on XEHPUK with PID 9756 (C:\Users\xehpuk\ws\foo\target\classes started by xehpuk in c:\Users\xehpuk\ws\foo)
2021-07-22 15:48:03.649  INFO 9756 --- [  restartedMain] de.xehpuk.foo.Application                : No active profile set, falling back to default profiles: default
2021-07-22 15:48:03.817  WARN 9756 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [de.xehpuk.foo.Controller] for bean with name 'controller' defined in file [C:\Users\xehpuk\ws\foo\target\classes\de\xehpuk\foo\Controller.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: Preview features are not enabled for de/xehpuk/foo/Controller (class file version 60.65535). Try running with '--enable-preview'
2021-07-22 15:48:03.821  INFO 9756 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-22 15:48:03.838 ERROR 9756 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [de.xehpuk.foo.Controller] for bean with name 'controller' defined in file [C:\Users\xehpuk\ws\foo\target\classes\de\xehpuk\foo\Controller.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: Preview features are not enabled for de/xehpuk/foo/Controller (class file version 60.65535). Try running with '--enable-preview'
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.8.jar:5.3.8]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.2.jar:2.5.2]
        at de.xehpuk.foo.Application.main(Application.java:10) ~[classes/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.5.2.jar:2.5.2]
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [de.xehpuk.foo.Controller] for bean with name 'controller' defined in file [C:\Users\xehpuk\ws\foo\target\classes\de\xehpuk\foo\Controller.class]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: Preview features are not enabled for de/xehpuk/foo/Controller (class file version 60.65535). Try running with '--enable-preview'
        at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1545) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:686) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:656) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:536) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:208) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) ~[spring-boot-2.5.2.jar:2.5.2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[spring-boot-2.5.2.jar:2.5.2]
        ... 13 common frames omitted
Caused by: java.lang.UnsupportedClassVersionError: Preview features are not enabled for de/xehpuk/foo/Controller (class file version 60.65535). Try running with '--enable-preview'
        at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010) ~[na:na]
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
        at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:512) ~[na:na]
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:420) ~[na:na]
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:414) ~[na:na]
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:691) ~[na:na]
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:413) ~[na:na]
        at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.findClass(RestartClassLoader.java:160) ~[spring-boot-devtools-2.5.2.jar:2.5.2]
        at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:142) ~[spring-boot-devtools-2.5.2.jar:2.5.2]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[na:na]
        at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
        at java.base/java.lang.Class.forName(Class.java:466) ~[na:na]
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:284) ~[spring-core-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:469) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1607) ~[spring-beans-5.3.8.jar:5.3.8]
        at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1534) ~[spring-beans-5.3.8.jar:5.3.8]
        ... 22 common frames omitted

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.5.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>de.xehpuk</groupId>
    <artifactId>foo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <java.version>16</java.version>
    </properties>
    <dependencies>
        <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>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我必须停止服务器,mvn cleanmvn spring-boot:run。怎么了?

5n0oy7gb

5n0oy7gb1#

似乎在您的代码中启用了预览功能
添加以下内容作为编译器选项。因此在编译时,您的IDE将显示警告和使用的预览特性的类路径
-Xlint:preview

相关问题