I upgraded Spring boot version 3.0.2 and i try graalvm nativeCompile that is error happened.
I run this application normal way it is OK but i try executable file show this error.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Unsatisfied dependency expressed through method 'setFilterChains' parameter 0: Error creating bean with name 'mvcHandlerMappingIntrospector': Error creating bean with name 'resourceHandlerMapping': Instantiation of supplied bean failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Unsatisfied dependency expressed through method 'setFilterChains' parameter 0: Error creating bean with name 'mvcHandlerMappingIntrospector': Error creating bean with name 'resourceHandlerMapping': Instantiation of supplied bean failed
i try use this annotation register bean , unfortunately repeat again error
@RegisterReflectionForBinding
that is my security configuration
@Configuration
@EnableMethodSecurity
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.headers()
.and()
.authorizeHttpRequests()
.anyRequest().authenticated()
.and()
.addFilterBefore(getAuthContext(),
UsernamePasswordAuthenticationFilter.class);
return httpSecurity.build();
}
@Bean
public AuthContextFilter1 getAuthContext() {
return new AuthContextFilter1();
}
}
that is my authContextFilter class
@Slf4j
public class AuthContextFilter1 extends GenericFilterBean {
private static final String X_CLIENT_ID = "ID";
private static final String X_CLIENT_ROLES = "ROLE";
private static final String ROLE_PREFIX = "ROLE_";
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Collection<GrantedAuthority> authorities = new ArrayList<>();
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String clientId = httpServletRequest.getHeader(X_CLIENT_ID);
String roles = httpServletRequest.getHeader(X_CLIENT_ROLES);
if (Objects.nonNull(clientId)) {
try {
if ((!StringUtils.isEmpty(roles))) {
authorities = Arrays.stream(roles.split(","))
.map(role -> new SimpleGrantedAuthority(ROLE_PREFIX + role))
.collect(Collectors.toList());
}
Authentication auth = new CustomAuthentication(clientId, authorities);
SecurityContextHolder.getContext().setAuthentication(auth);
} catch (Exception e) {
log.error("Auth context initialization failed for clientId: {}, message: {}",
clientId, e.getMessage());
}
}
chain.doFilter(request, response);
}
}
I have had the same problem, and the cause was the dependency "springdoc-openapi-ui".
// implementation("org.springdoc:springdoc-openapi-ui:1.6.14")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2")