При запуске приложения в Azure мы получаем следующее исключение.
Код: Выделить всё
2024-03-31T10:33:10 PID[6060] Error Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'securityFilterChain' threw exception with message: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher). 2024-03-31T10:33:10 PID[6060] Error 2024-03-31T10:33:10 PID[6060] Error This is because there is more than one mappable servlet in your servlet context: {org.apache.jasper.servlet.JspServlet=[*.jspx, *.jsp], org.springframework.web.servlet.DispatcherServlet=[/]}. 2024-03-31T10:33:10 PID[6060] Error 2024-03-31T10:33:10 PID[6060] Error For each MvcRequestMatcher, call MvcRequestMatcher#setServletPath to indicate the servlet path. 2024-03-31T10:33:10 PID[6060] Error at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) 2024-03-31T10:33:10 PID[6060] Error at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) 2024-03-31T10:33:10 PID[6060] Error ... 77 more 2024-03-31T10:33:10 PID[6060] Error Caused by: java.lang.IllegalArgumentException: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher). 2024-03-31T10:33:10 PID[6060] Error 2024-03-31T10:33:10 PID[6060] Error This is because there is more than one mappable servlet in your servlet context: {org.apache.jasper.servlet.JspServlet=[*.jspx, *.jsp], org.springframework.web.servlet.DispatcherServlet=[/]}. 2024-03-31T10:33:10 PID[6060] Error 2024-03-31T10:33:10 PID[6060] Error For each MvcRequestMatcher, call MvcRequestMatcher#setServletPath to indicate the servlet path. 2024-03-31T10:33:10 PID[6060] Error at org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry.requestMatchers(AbstractRequestMatcherRegistry.java:208) 2024-03-31T10:33:10 PID[6060] Error at org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry.requestMatchers(AbstractRequestMatcherRegistry.java:276) 2024-03-31T10:33:10 PID[6060] Error at com.xx.app1.security.SecurityConfiguration.lambda$securityFilterChain$0(SecurityConfiguration.java:41) 2024-03-31T10:33:10 PID[6060] Error at org.springframework.security.config.annotation.web.builders.HttpSecurity.authorizeHttpRequests(HttpSecurity.java:1466) 2024-03-31T10:33:10 PID[6060] Error at com.xx.app1.security.SecurityConfiguration.securityFilterChain(SecurityConfiguration.java:40) 2024-03-31T10:33:10 PID[6060] Error at com.xx.app1.security.SecurityConfiguration$$SpringCGLIB$$0.CGLIB$securityFilterChain$1() 2024-03-31T10:33:10 PID[6060] Error at com.xx.app1.security.SecurityConfiguration$$SpringCGLIB$$FastClass$$1.invoke() 2024-03-31T10:33:10 PID[6060] Error at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) 2024-03-31T10:33:10 PID[6060] Error at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) 2024-03-31T10:33:10 PID[6060] Error at com.xx.app1.security.SecurityConfiguration$$SpringCGLIB$$0.securityFilterChain() 2024-03-31T10:33:10 PID[6060] Error at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2024-03-31T10:33:10 PID[6060] Error at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 2024-03-31T10:33:10 PID[6060] Error at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2024-03-31T10:33:11 PID[6060] Error at java.base/java.lang.reflect.Method.invoke(Method.java:568) 2024-03-31T10:33:11 PID[6060] Error at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) 2024-03-31T10:33:11 PID[6060] Error ... 78 moreКод: Выделить всё
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {
private final JwtAuthenticationFilter jwtAuthenticationFilter;
private final UserService userService;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
request -> request.requestMatchers("/**").permitAll().anyRequest().authenticated())
.sessionManagement(manager -> manager.sessionCreationPolicy(STATELESS))
.authenticationProvider(authenticationProvider())
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
http.cors();
return http.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userService.userDetailsService());
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}
}
Tomcat 10.1 и JDK 17 настраиваются в службе приложений Azure
Подробнее здесь: https://stackoverflow.com/questions/782 ... pp-service