springboot版本问题

在学习mybatisplus时 启动spring项目 出现了以下问题:

Error:(3, 32) java: 无法访问org.springframework.boot.SpringApplication
  错误的类文件: /D:/Develop Java/Java installation software location/maven/3.3.9/Repository/org/springframework/boot/spring-boot/3.0.3/spring-boot-3.0.3.jar!/org/springframework/boot/SpringApplication.class
    类文件具有错误的版本 61.0, 应为 52.0
    请删除该文件或确保该文件位于正确的类路径子目录中。

这是Springboot的版本和Java的版本不对应导致的。

Springboot2.0以上版本最低需要java8支持;
Springboot3.0以上的版本最低需要java17支持!

springboot有什么版本可以去spring官网看 https://spring.io/projects/spring-boot#learn

我观察了一下我用springboot版本 发现用到3.0以上

在观察我的JDk 发现我用的jdk是1.8

所以根本的问题在于我的springboot的版本和JDK的版本无法匹配

这时 我们主要把springboot的版本改小点就可以 我这里面把它修改成2.7.6dna

成功运行

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Spring Boot版本中,跨域问题可以通过添加CORS(跨域资源共享)配置来解决。 1. 添加依赖 在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> ``` 2. 配置CORS 在Spring Boot中,可以通过添加@Configuration注解和@EnableWebMvc注解来配置CORS: ``` @Configuration @EnableWebMvc public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("GET", "POST", "PUT", "DELETE") .allowedHeaders("*") .allowCredentials(true) .maxAge(3600); } } ``` 以上代码配置了允许所有来源的请求(allowedOrigins("*")),允许的请求方法为GET、POST、PUT和DELETE(allowedMethods("GET", "POST", "PUT", "DELETE")),允许的请求头为所有(allowedHeaders("*")),允许携带凭证(allowCredentials(true)),并设置了缓存时间为3600秒(maxAge(3600))。 3. 配置全局拦截器 在Spring Boot中,还可以通过配置全局拦截器来解决跨域问题: ``` @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new CorsInterceptor()) .addPathPatterns("/**"); } } ``` 以上代码配置了一个全局拦截器CorsInterceptor,拦截所有请求(addPathPatterns("/**"))。 4. 配置Filter 在Spring Boot中,还可以通过配置Filter来解决跨域问题: ``` @Bean public FilterRegistrationBean<CorsFilter> corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.addAllowedOrigin("*"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); source.registerCorsConfiguration("/**", config); FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source)); bean.setOrder(Ordered.HIGHEST_PRECEDENCE); return bean; } ``` 以上代码配置了一个CorsFilter,允许所有来源的请求(config.addAllowedOrigin("*")),允许所有请求头(config.addAllowedHeader("*")),允许所有请求方法(config.addAllowedMethod("*")),并设置了允许携带凭证(config.setAllowCredentials(true))。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值