org.springframework.boot:spring-boot-starter-parent从2.1.5.RELEASE换到2.4.3,导致出现错误。

报错

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-22 14:43:31,813 ERROR [main] o.s.b.d.LoggingFailureAnalysisReporter [LoggingFailureAnalysisReporter.java:40] 

***************************
APPLICATION FAILED TO START
***************************

Description:

Invalid mapping pattern detected: /**/*.css
^
No more pattern data allowed after {*...} or ** pattern element

Action:

Fix this pattern in your application or switch to the legacy parser implementation with `spring.mvc.pathpattern.matching-strategy=ant_path_matcher`.

解决

spring mvc报错:No more pattern data allowed after {*…} or ** pattern element

复制上文:

原因:
错误是路径通配问题,查找发现是spring升级到5.3之后路径通配发生了变化,官方给出的解释是“In Spring MVC, the path was previously analyzed by AntPathMatcher, but it was changed to use PathPatternParser introduced in WebFlux from Spring 5.3.0.”。

解决:
具体解决是把/**/*.css改为/*/*.css,项目中可能涉及多个文件,都要改。

具体改哪里

拦截器要改,改为"/*":
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AlphaInterceptor alphaInterceptor;
	
	。。。

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(alphaInterceptor)
                .excludePathPatterns("/*/*.css", "/*/*.js", "/*/*.png", "/*/*.jpg", "/*/*.jpeg")
                .addPathPatterns("/register", "/login");

		。。。
    }
}
SpringSecurity的配置类不用改,继续"/**":
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter implements CommunityConstant {

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**");
    }

	。。。
}

转载自:spring mvc报错:No more pattern data allowed after {*…} or ** pattern element

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐