java: 无法访问org.springframework.web.servlet.config.annotation.CorsRegistry 错误的类文件: /F:/UserYan/idea/maven/repository/org/springframework/spring-webmvc/6.0.9/spring-webmvc-6.0.9.jar!/org/springframework/web/servlet/config/annotation/CorsRegistry.class
时间: 2023-07-11 18:56:29 浏览: 48
根据您提供的错误信息,可能是由于版本不兼容导致的。具体来说,您的项目中引用的Spring Web MVC版本为6.0.9,但是实际上最新版本为5.x,其中CorsRegistry类位于org.springframework.web.servlet.config.annotation包下,而不是org.springframework.web.servlet.config.annotation.annotation包下。
解决办法如下:
1. 确认您的项目中引用的Spring Web MVC版本是否正确。建议使用最新版本的Spring Boot,它会自动管理依赖关系。
2. 如果您的项目中确实需要使用6.0.9版本的Spring Web MVC,则需要手动将CorsRegistry类从org.springframework.web.servlet.config.annotation.annotation包下移动到org.springframework.web.servlet.config.annotation包下。可以通过从源代码中复制CorsRegistry类并将其粘贴到正确的包中来实现。
希望这些信息能够帮助您解决问题。如果还有其他问题,请随时提出。
相关问题
启动项目时显示java: 程序包org.springframework.web.servlet.config.annotation不存在
这个问题可能是因为您缺少了Spring MVC的配置。您可以尝试在您的代码中添加以下依赖关系:
```
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>当前版本号</version>
</dependency>
```
如果您已经添加了这个依赖项,那么您需要检查您的代码是否正确配置了Spring MVC。您可以查看以下链接获取有关Spring MVC配置的更多信息:
https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc
希望这可以帮助您解决问题!
java: 程序包org.springframework.web.servlet.config.annotation不存在,怎么添加相应的依赖
你可以在你的项目的 pom.xml 文件中添加如下的依赖:
```xml
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
</dependencies>
```
这个依赖包含了 Spring 的 web 框架所需要的类库。然后再重新编译一下你的项目,就应该可以解决这个错误了。