o.s.b.d.LoggingFailureAnalysisReporter。Invalid mapping pattern detected: /**/*.css。No more pattern。。


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值