Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception 解决跨域问题

首先在这里说声抱歉,之前在文章上立下的flag倒了,因为这段时间我要准备期末考试,所以就顾不上这边的文章发布了,明天还有一门考试,我也是抽时间赶紧把我在前段时间遇到的问题发出来期望对大家有帮助。

这是我在使用@Configration注解解决跨域问题时遇到的新问题,当时也百度了,说是Service层实现类未添加注解@Autowired或者说是Controller层没有加@ResponseBody但是我是添加了Autowired注解的,在Controller层又新加了@ResponseBody注解但都没有解决问题。

先看一下我之前写的代码:

@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")              
                .allowCredentials(true)
                .allowedMethods("*")
                .maxAge(3600);
    }
}

这段代码实现跨域和网上的代码是一样的或者相似的,但还是报错。

最后解决代码:

@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public

你可能感兴趣的:(java,spring,boot,后端,maven)