spring oauth2 server grant by password Access is denied (user is anonymous) - spring

I try to setup a authserver, but when it get token in Advance rest client,it can't grant by password and input basic user and password Access is denied (user is anonymous)
2017-03-23 21:18:56.788[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', PUT]
[2m2017-03-23 21:18:56.788[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'GET /oauth/token' doesn't match 'PUT /logout
[2m2017-03-23 21:18:56.789[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', DELETE]
[2m2017-03-23 21:18:56.789[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'GET /oauth/token' doesn't match 'DELETE /logout
[2m2017-03-23 21:18:56.789[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m No matches found
[2m2017-03-23 21:18:56.789[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 5 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
[2m2017-03-23 21:18:56.790[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
[2m2017-03-23 21:18:56.790[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
[2m2017-03-23 21:18:56.792[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
[2m2017-03-23 21:18:56.795[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.a.AnonymousAuthenticationFilter [0;39m [2m:[0;39m Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken#9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails#b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
[2m2017-03-23 21:18:56.796[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter'
[2m2017-03-23 21:18:56.796[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.session.SessionManagementFilter [0;39m [2m:[0;39m Requested session ID 72A53EBFC2683D7F4CEAF0BF51D76993 is invalid.
[2m2017-03-23 21:18:56.796[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
[2m2017-03-23 21:18:56.796[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
[2m2017-03-23 21:18:56.798[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/oauth/token'; against '/oauth/token'
[2m2017-03-23 21:18:56.798[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.a.i.FilterSecurityInterceptor [0;39m [2m:[0;39m Secure object: FilterInvocation: URL: /oauth/token?client_id=client&client_secret=secret&grant_type=password&username=reader&password=reader; Attributes: [fullyAuthenticated]
[2m2017-03-23 21:18:56.798[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.a.i.FilterSecurityInterceptor [0;39m [2m:[0;39m Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken#9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails#b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS
[2m2017-03-23 21:18:56.804[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.access.vote.AffirmativeBased [0;39m [2m:[0;39m Voter: org.springframework.security.web.access.expression.WebExpressionVoter#5f5f5614, returned: -1
[2m2017-03-23 21:18:56.814[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.a.ExceptionTranslationFilter [0;39m [2m:[0;39m Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84) ~[spring-security-core-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233) ~[spring-security-core-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) [spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) [spring-boot-actuator-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.11.jar:8.5.11]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar:8.5.11]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
[2m2017-03-23 21:18:56.819[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.util.matcher.AndRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/**', GET]
[2m2017-03-23 21:18:56.820[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request '/oauth/token' matched by universal pattern '/**'
[2m2017-03-23 21:18:56.820[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.util.matcher.AndRequestMatcher [0;39m [2m:[0;39m Trying to match using NegatedRequestMatcher [requestMatcher=Ant [pattern='/**/favicon.ico']]
[2m2017-03-23 21:18:56.820[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/oauth/token'; against '/**/favicon.ico'
[2m2017-03-23 21:18:56.820[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.matcher.NegatedRequestMatcher [0;39m [2m:[0;39m matches = true
[2m2017-03-23 21:18:56.820[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.util.matcher.AndRequestMatcher [0;39m [2m:[0;39m Trying to match using NegatedRequestMatcher [requestMatcher=MediaTypeRequestMatcher [contentNegotiationStrategy=org.springframework.web.accept.ContentNegotiationManager#78e22d35, matchingMediaTypes=[application/json], useEquals=false, ignoredMediaTypes=[*/*]]]
[2m2017-03-23 21:18:56.825[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.m.MediaTypeRequestMatcher [0;39m [2m:[0;39m httpRequestMediaTypes=[]
[2m2017-03-23 21:18:56.826[0;39m [32mDEBUG[0;39m [35m7000[0;39m [2m---[0;39m [2m[nio-7777-exec-1][0;39m [36mo.s.s.w.u.m.MediaTypeRequestMatcher [0;39m [2m:[0;39m Did not match any media types
here is my code
#SpringBootApplication
//#EnableResourceServer
#RestController
public class AuthServiceApplication {
#RequestMapping("/user")
public Principal user(Principal user) {
return user;
}
public static void main(String[] args) {
SpringApplication.run(AuthServiceApplication.class, args);
}
}
WebSecurityConfig
#Configuration
#EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// #Autowired
// private DataSource dataSource;
// #Autowired
// public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth
// .jdbcAuthentication()
// .dataSource(dataSource);//设置为从数据库读取用户认证信息(JdbcUserdetailsService)
// }
#Override
protected void configure(HttpSecurity http) throws Exception {
// http.anonymous().disable()
// .authorizeRequests()
// .anyRequest().authenticated();
// http
// .csrf().disable()
//// .exceptionHandling()
//// .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))
// .and()
// .authorizeRequests()
// .antMatchers("/**").authenticated()
// .and()
// .httpBasic();
http.authorizeRequests().antMatchers("/oauth/**", "/login", "/signup", "/forgotPassword").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll();
}
#Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// TODO Auto-generated method stub
// super.configure(auth);
auth
// .parentAuthenticationManager(authenticationManagerBean())
.inMemoryAuthentication()
.withUser("reader")
.password("reader")
// .authorities("FOO_READ")
.roles("USERS")
.and()
.withUser("writer")
.password("writer")
.authorities("FOO_READ", "FOO_WRITE");
}
#Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/hystrix.stream/**", "/info", "/error");
}
// #Bean
// #Override
// protected AuthenticationManager authenticationManager() throws Exception {
// // TODO Auto-generated method stub
// return super.authenticationManager();
// }
#Bean
#Override
public AuthenticationManager authenticationManagerBean() throws Exception {
// TODO Auto-generated method stub
return super.authenticationManagerBean();
}
}
AuthServerConfig
#Configuration
#EnableAuthorizationServer
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
// Logger logger = Logger.getLogger(this.getClass().getName());
#Autowired
#Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
// #Autowired
// InMemoryTokenStore tokenStore;
// #Bean
// public TokenStore tokenStore() {
// return new InMemoryTokenStore();
// }
#Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
// TODO Auto-generated method stub
// super.configure(endpoints);
endpoints
// .tokenStore(tokenStore())
.authenticationManager(authenticationManager);
}
#Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// TODO Auto-generated method stub
// super.configure(clients);
clients.inMemory() // 使用in-memory存储
.withClient("client") // client_id
.secret("secret") // client_secret
.authorizedGrantTypes("implicit", "authorization_code", "refresh_token", "password");// 该client允许的授权类型
// .scopes("read", "write", "trust"); // 允许的授权范围
}
#Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
// TODO Auto-generated method stub
// super.configure(security);
security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()");
// security.tokenKeyAccess("permitAll()");//公开/oauth/token的接口
}
}

Did you try removing roles and authorities?

Related

Eureka Server Exception starting filter [servletContainer] error and Eureka Server not starting

I have made a Eureka Server in Spring Tool Suite but when I am running it as a Spring Application I am getting this error:
[2m2022-12-05 13:15:10.439[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.c.c.ConfigServicePropertySourceLocator[0;39m [2m:[0;39m Fetching config from server at : http://localhost:8888
[2m2022-12-05 13:15:10.564[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.c.c.ConfigServicePropertySourceLocator[0;39m [2m:[0;39m Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
[2m2022-12-05 13:15:10.564[0;39m [33m WARN[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.c.c.ConfigServicePropertySourceLocator[0;39m [2m:[0;39m Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/Eureka-server/default": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
[2m2022-12-05 13:15:10.566[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mcom.vipul.EurekaServerApplication [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2022-12-05 13:15:11.405[0;39m [33m WARN[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.boot.actuate.endpoint.EndpointId [0;39m [2m:[0;39m Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
[2m2022-12-05 13:15:11.735[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.cloud.context.scope.GenericScope [0;39m [2m:[0;39m BeanFactory id=0c9a9003-56ac-33ba-b45b-bb86d98d68ff
[2m2022-12-05 13:15:11.828[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mtrationDelegate$BeanPostProcessorChecker[0;39m [2m:[0;39m Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$5cbea4b1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2m2022-12-05 13:15:12.188[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 5055 (http)
[2m2022-12-05 13:15:12.217[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2022-12-05 13:15:12.217[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet Engine: Apache Tomcat/9.0.12
[2m2022-12-05 13:15:12.231[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.catalina.core.AprLifecycleListener [0;39m [2m:[0;39m The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Users\sbans\Downloads\sts-4.16.1.RELEASE\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.4.v20221004-1257\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Users/sbans/Downloads/sts-4.16.1.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.4.v20221004-1257/jre/bin/server;C:/Users/sbans/Downloads/sts-4.16.1.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.4.v20221004-1257/jre/bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;%sbans%\AppData\Roaming\Composer\vendor\bin;C:\Program Files\Java\jdk1.8.0_151\bin;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2019b\bin;C:\Program Files\PuTTY\;C:\Program Files\nodejs\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\sbans\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\sbans\AppData\Local\Programs\Python\Python37\;C:\Users\sbans\AppData\Local\Microsoft\WindowsApps;C:\Users\sbans\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\sbans\AppData\Roaming\Composer\vendor\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.3\bin;;C:\Program Files\Oracle\VirtualBox;C:\Users\sbans\AppData\Roaming\npm;C:\Program Files\Java\jdk-17.0.5;;C:\Users\sbans\Downloads\sts-4.16.1.RELEASE;;.]
[2m2022-12-05 13:15:12.443[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2022-12-05 13:15:12.443[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.web.context.ContextLoader [0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 1857 ms
[2m2022-12-05 13:15:12.583[0;39m [33m WARN[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.n.c.sources.URLConfigurationSource [0;39m [2m:[0;39m No URLs will be polled as dynamic configuration sources.
[2m2022-12-05 13:15:12.584[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.n.c.sources.URLConfigurationSource [0;39m [2m:[0;39m To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
[2m2022-12-05 13:15:12.603[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.netflix.config.DynamicPropertyFactory [0;39m [2m:[0;39m DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#2616b618
[2m2022-12-05 13:15:14.239[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.cloud.commons.util.InetUtils [0;39m [2m:[0;39m Cannot determine local hostname
[2m2022-12-05 13:15:15.448[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.cloud.commons.util.InetUtils [0;39m [2m:[0;39m Cannot determine local hostname
[2m2022-12-05 13:15:15.676[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'characterEncodingFilter' to: [/*]
[2m2022-12-05 13:15:15.676[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'webMvcMetricsFilter' to: [/*]
[2m2022-12-05 13:15:15.677[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
[2m2022-12-05 13:15:15.677[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'formContentFilter' to: [/*]
[2m2022-12-05 13:15:15.677[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'requestContextFilter' to: [/*]
[2m2022-12-05 13:15:15.677[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'httpTraceFilter' to: [/*]
[2m2022-12-05 13:15:15.677[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.FilterRegistrationBean [0;39m [2m:[0;39m Mapping filter: 'servletContainer' to urls: [/eureka/*]
[2m2022-12-05 13:15:15.677[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.servlet.ServletRegistrationBean [0;39m [2m:[0;39m Servlet dispatcherServlet mapped to [/]
[2m2022-12-05 13:15:15.794[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.s.j.s.i.a.WebApplicationImpl [0;39m [2m:[0;39m Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'
[2m2022-12-05 13:15:15.871[0;39m [31mERROR[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Exception starting filter [servletContainer]
[2m2022-12-05 13:15:15.873[0;39m [31mERROR[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardContext [0;39m [2m:[0;39m One or more Filters failed to start. Full details will be found in the appropriate container log file
[2m2022-12-05 13:15:15.873[0;39m [31mERROR[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardContext [0;39m [2m:[0;39m Context [] startup failed due to previous errors
[2m2022-12-05 13:15:15.879[0;39m [33m WARN[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.c.loader.WebappClassLoaderBase [0;39m [2m:[0;39m The web application [ROOT] appears to have started a thread named [spring.cloud.inetutils] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.base#17.0.4.1/java.net.Inet6AddressImpl.getHostByAddr(Native Method)
java.base#17.0.4.1/java.net.InetAddress$PlatformNameService.getHostByAddr(InetAddress.java:939)
java.base#17.0.4.1/java.net.InetAddress.getHostFromNameService(InetAddress.java:662)
java.base#17.0.4.1/java.net.InetAddress.getHostName(InetAddress.java:605)
java.base#17.0.4.1/java.net.InetAddress.getHostName(InetAddress.java:577)
app//org.springframework.cloud.commons.util.InetUtils$$Lambda$189/0x00000001002793e8.call(Unknown Source)
java.base#17.0.4.1/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base#17.0.4.1/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base#17.0.4.1/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base#17.0.4.1/java.lang.Thread.run(Thread.java:833)
[2m2022-12-05 13:15:15.882[0;39m [31mERROR[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36morg.apache.catalina.core.ContainerBase [0;39m [2m:[0;39m A child container failed during start
[2m2022-12-05 13:15:15.884[0;39m [31mERROR[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36morg.apache.catalina.core.ContainerBase [0;39m [2m:[0;39m A child container failed during start
[2m2022-12-05 13:15:15.884[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Stopping service [Tomcat]
[2m2022-12-05 13:15:15.885[0;39m [33m WARN[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mConfigServletWebServerApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
[2m2022-12-05 13:15:15.901[0;39m [32m INFO[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mConditionEvaluationReportLoggingListener[0;39m [2m:[0;39m
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2022-12-05 13:15:15.904[0;39m [31mERROR[0;39m [35m12152[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.vipul.EurekaServerApplication.main(EurekaServerApplication.java:12) ~[classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:125) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:414) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 8 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:960) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:261) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:370) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:106) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 13 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na]
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
... 21 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:960) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145) ~[na:na]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:944) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
... 21 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to stop component [WebappLoader[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na]
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:951) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
... 29 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [WebappLoader[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:267) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5367) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:187) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145) ~[na:na]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:944) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
... 29 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field static final java.io.ClassCache java.io.ObjectStreamClass$Caches.localDescs accessible: module java.base does not "opens java.io" to unnamed module #5965d37
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) ~[na:na]
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172) ~[na:na]
at org.apache.catalina.loader.WebappClassLoaderBase.clearCache(WebappClassLoaderBase.java:2206) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches(WebappClassLoaderBase.java:2194) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1567) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1497) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.loader.WebappLoader.stopInternal(WebappLoader.java:442) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
... 38 common frames omitted
Here is my POM.XML for Eureka Server:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vipul</groupId>
<artifactId>EurekaServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>EurekaServer</name>
<description>Project for Eureka Server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
Here is application.properties for Eureka Server:
spring.application.name=Eureka-server
server.port=5055
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
eureka.client.service-url.defaultZone=http://localhost:5055/eureka
My configuration server is working but I am not able to start the Eureka server due to this.
Can anyone help to resolve this error as I am not able to fix this.

MVC project Role based authentication for admin and normal user using database for getting role details

The Role-based authentication system where there will be some admin and some normal users. I am trying to configure the system in such a way that depending on the role of the user they will be able to login using different URLs and after that, they can perform their intended task. The following code is used for the configuration
This is for userDetail
package com.multiauthentication.config;
import java.util.Collection;
import java.util.List;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.multiauthentication.entity.User;
public class CustomUserDetails implements UserDetails {
private User user;
public CustomUserDetails(User user) {
this.user = user;
}
#Override
public Collection<? extends GrantedAuthority> getAuthorities() {
SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(user.getUserRole());
return List.of(simpleGrantedAuthority);
}
#Override
public String getPassword() {
return user.getPassword();
}
#Override
public String getUsername() {
return user.getEmailAddress();
}
#Override
public boolean isAccountNonExpired() {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean isAccountNonLocked() {
return true;
}
#Override
public boolean isCredentialsNonExpired() {
return true;
}
#Override
public boolean isEnabled() {
return true;
}
}
This is for userService detail
package com.multiauthentication.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import com.multiauthentication.config.CustomUserDetails;
import com.multiauthentication.dao.UserRepository;
import com.multiauthentication.entity.User;
public class UserDetailsServiceImpl implements UserDetailsService{
#Autowired
private UserRepository userRepository;
#Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// Fetch user from Database
User user = this.userRepository.getUserByUserEmail(username);
if(user == null) {
throw new UsernameNotFoundException("Could not found user");
}
CustomUserDetails userDetails = new CustomUserDetails(user);
return userDetails;
}
}
And this is for application configuration
package com.multiauthentication.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import com.multiauthentication.service.UserDetailsServiceImpl;
#Configuration
#EnableWebSecurity
public class WebConfig {
#Bean
public UserDetailsService getDetailsService() {
return new UserDetailsServiceImpl();
}
#Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
#Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService(this.getDetailsService());
daoAuthenticationProvider.setPasswordEncoder(this.passwordEncoder());
return daoAuthenticationProvider;
}
// Configure Method
#Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration)
throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
#Configuration
#Order(1)
public static class AppConfigurationAdapter1 {
// Configure HttpSecurity for Admin
#Bean
protected SecurityFilterChain filterChain1(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.and()
.formLogin()
.loginPage("/loginAdmin")
.loginProcessingUrl("/admin_login")
.defaultSuccessUrl("/admin/index")
.and()
.logout()
.logoutUrl("/admin_logout")
.logoutSuccessUrl("/protectedLinks")
.deleteCookies("JSESSIONID")
.and()
.exceptionHandling()
.accessDeniedPage("/403")
.and()
.csrf().disable();
return http.build();
}
}
#Configuration
#Order(2)
public static class AppConfigurationAdapter2 {
// Configure HttpSecurity for User
#Bean
protected SecurityFilterChain filterChain2(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.antMatchers("/user/**").hasRole("NORMAL")
.and()
.formLogin()
.loginPage("/loginUser")
.loginProcessingUrl("/user_login")
.defaultSuccessUrl("/user/index")
.and()
.logout()
.logoutUrl("/user_logout")
.logoutSuccessUrl("/protectedLinks")
.deleteCookies("JSESSIONID")
.and()
.exceptionHandling()
.accessDeniedPage("/403")
.and()
.csrf().disable();
return http.build();
}
}
}
The entity class is defined and declared in the following way
package com.multiauthentication.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
#Entity
#Table(name = "users")
#Getter
#Setter
#NoArgsConstructor
#AllArgsConstructor
#ToString
public class User {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id")
private int id;
#Column(name = "user_name")
private String userName;
#Column(name = "email_address")
private String emailAddress;
#Column(name = "password")
private String password;
#Column(name = "user_role")
private String userRole;
#Column(name = "user_enabled")
private boolean userEnabled;
}
The login for Admin is properly working and able to hit the defaultSuccessUrl("/admin/index") but for the normal it is not. Whenever the I tried to login using credentials of normal user it get stuck on loginProcessingUrl("/user_login") for your reference I am attaching both page for user login and response after that I get.
The Following logs is related to admin role which is successfull
2022-10-23 09:49:16.992[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/loginAdmin", parameters={}
[2m2022-10-23 09:49:16.993[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to com.multiauthentication.controller.BasicController#customAdminLogin(Model)
[2m2022-10-23 09:49:16.996[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36mo.s.w.s.v.ContentNegotiatingViewResolver[0;39m [2m:[0;39m Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
[2m2022-10-23 09:49:17.039[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-8][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:49:17.050[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/CSS/style.css", parameters={}
[2m2022-10-23 09:49:17.050[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[io-8080-exec-10][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/JS/scriptfile.js", parameters={}
[2m2022-10-23 09:49:17.051[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:49:17.051[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[io-8080-exec-10][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:49:17.052[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[io-8080-exec-10][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:49:17.052[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
Hibernate: select user0_.id as id1_0_, user0_.email_address as email_ad2_0_, user0_.password as password3_0_, user0_.user_enabled as user_ena4_0_, user0_.user_name as user_nam5_0_, user0_.user_role as user_rol6_0_ from users user0_ where user0_.email_address=?
[2m2022-10-23 09:49:31.751[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/admin/index", parameters={}
[2m2022-10-23 09:49:31.751[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to com.multiauthentication.controller.AdminController#showHomeAdmin(Model, Principal)
Hibernate: select user0_.id as id1_0_, user0_.email_address as email_ad2_0_, user0_.password as password3_0_, user0_.user_enabled as user_ena4_0_, user0_.user_name as user_nam5_0_, user0_.user_role as user_rol6_0_ from users user0_ where user0_.email_address=?
[2m2022-10-23 09:49:31.758[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.w.s.v.ContentNegotiatingViewResolver[0;39m [2m:[0;39m Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
[2m2022-10-23 09:49:31.782[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:49:31.791[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-3][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/CSS/style.css", parameters={}
[2m2022-10-23 09:49:31.792[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-3][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:49:31.794[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-4][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/JS/scriptfile.js", parameters={}
[2m2022-10-23 09:49:31.794[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-3][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:49:31.795[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-4][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:49:31.797[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-4][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:49:32.158[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-5][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/Image/Urban%20development%20Banner.png", parameters={}
[2m2022-10-23 09:49:32.158[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-5][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:49:32.162[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-5][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
And now this log is related to normal role which is not working properly
[2m2022-10-23 09:55:37.407[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/loginUser", parameters={}
[2m2022-10-23 09:55:37.408[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to com.multiauthentication.controller.BasicController#customUserLogin(Model)
[2m2022-10-23 09:55:37.411[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36mo.s.w.s.v.ContentNegotiatingViewResolver[0;39m [2m:[0;39m Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
[2m2022-10-23 09:55:37.455[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-9][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:55:37.462[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[io-8080-exec-10][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/CSS/style.css", parameters={}
[2m2022-10-23 09:55:37.462[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m GET "/JS/scriptfile.js", parameters={}
[2m2022-10-23 09:55:37.463[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:55:37.463[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[io-8080-exec-10][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:55:37.465[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:55:37.465[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[io-8080-exec-10][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 200 OK
[2m2022-10-23 09:55:56.532[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m POST "/user_login", parameters={masked}
[2m2022-10-23 09:55:56.533[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
[2m2022-10-23 09:55:56.540[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.w.s.r.ResourceHttpRequestHandler [0;39m [2m:[0;39m Resource not found
[2m2022-10-23 09:55:56.541[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed 404 NOT_FOUND
[2m2022-10-23 09:55:56.542[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m "ERROR" dispatch for POST "/error", parameters={masked}
[2m2022-10-23 09:55:56.542[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
[2m2022-10-23 09:55:56.562[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.w.s.v.ContentNegotiatingViewResolver[0;39m [2m:[0;39m Selected 'text/html' given [text/html, text/html;q=0.8]
[2m2022-10-23 09:55:56.562[0;39m [32mDEBUG[0;39m [35m13680[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Exiting from "ERROR" dispatch, status 404

Spring boot 4 controller error: The method save(S) in the type CrudRepository<Fournisseur,Long> is not applicable for the arguments (Fournisseur)

I'am new with spring boot. I'am using Spring boot (4) data JPA and MySQL. The method findall worked fine for me for the class fournisseur but the save method wont work.
Here my class:
package net.javaguides.springboot.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name ="fournisseur")
public class Fournisseur {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long ID;
#Column(name="Name")
private String Name;
#Column(name="Address")
private String Address;
#Column(name="Phone")
private long Phone;
public Fournisseur() {
}
public Fournisseur(String name, String address, long phone) {
super();
Name = name;
Address = address;
Phone = phone;
}
public long getID() {
return ID;
}
public void setID(long iD) {
this.ID = iD;
}
public String getName() {
return Name;
}
public void setName(String name) {
this.Name = name;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
this.Address = address;
}
public long getPhone() {
return Phone;
}
public void setPhone(long phone) {
this.Phone = phone;
}
}
Here my Repository:
package net.javaguides.springboot.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import net.javaguides.springboot.model.Fournisseur;
#Repository
public interface FournisseurRepository extends JpaRepository<Fournisseur,Long> {
}
Here my controller:
package net.javaguides.springboot.controller;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.javaguides.springboot.repository.FournisseurRepository;
#CrossOrigin(origins ="http://localhost:4200",maxAge=3600)
#RestController
#RequestMapping("/api/v1/")
public class FournisseurController<Fournisseur, Fournisseurs> {
#Autowired
private FournisseurRepository fournisseurRepository;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long ID;
//get all employee
#GetMapping("/fournisseurs")
public java.util.List<net .javaguides.springboot.model.Fournisseur> getAllFournisseurs(){
return fournisseurRepository.findAll();
}
#PostMapping("/fournisseurs")
public Fournisseur createFournisseur(#RequestBody Fournisseur fournisseur){
return fournisseurRepository.save(fournisseur);
}
}
When running the application and use postman to post data it returns the following error:
{
"timestamp": "2021-12-13T22:06:19.958+00:00",
"status": 500,
"error": "Internal Server Error",
"trace": "java.lang.Error: Unresolved compilation problem: \n\tThe method save(S) in the type CrudRepository<Fournisseur,Long> is not applicable for the arguments (Fournisseur)\n\r\n\tat net.javaguides.springboot.controller.FournisseurController.createFournisseur(FournisseurController.java:33)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)\r\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:568)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)\r\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:681)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:764)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)\r\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)\r\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\r\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)\r\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\r\n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)\r\n\tat org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.base/java.lang.Thread.run(Thread.java:833)\r\n",
"message": "Unresolved compilation problem: \n\tThe method save(S) in the type CrudRepository<Fournisseur,Long> is not applicable for the arguments (Fournisseur)\n",
"path": "/api/v1/fournisseurs"
}
And the IDE returns the following:
23:06:03.283 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#33c8d704
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m [2m (v2.6.1)[0;39m
[2m2021-12-13 23:06:03.538[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mn.j.springboot.StockApplication [0;39m [2m:[0;39m Starting StockApplication using Java 17 on DESKTOP-BNFECFD with PID 19252 (C:\STS\Stock\target\classes started by ACER in C:\STS\Stock)
[2m2021-12-13 23:06:03.538[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mn.j.springboot.StockApplication [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2021-12-13 23:06:03.573[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
[2m2021-12-13 23:06:03.573[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
[2m2021-12-13 23:06:03.966[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[2m2021-12-13 23:06:04.001[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Finished Spring Data repository scanning in 29 ms. Found 1 JPA repository interfaces.
[2m2021-12-13 23:06:04.374[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2021-12-13 23:06:04.380[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2021-12-13 23:06:04.381[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/9.0.55]
[2m2021-12-13 23:06:04.433[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2021-12-13 23:06:04.433[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 860 ms
[2m2021-12-13 23:06:04.528[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Starting...
[2m2021-12-13 23:06:04.628[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Start completed.
[2m2021-12-13 23:06:04.655[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.hibernate.jpa.internal.util.LogHelper [0;39m [2m:[0;39m HHH000204: Processing PersistenceUnitInfo [name: default]
[2m2021-12-13 23:06:04.685[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36morg.hibernate.Version [0;39m [2m:[0;39m HHH000412: Hibernate ORM core version 5.6.1.Final
[2m2021-12-13 23:06:04.785[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.hibernate.annotations.common.Version [0;39m [2m:[0;39m HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
[2m2021-12-13 23:06:04.850[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36morg.hibernate.dialect.Dialect [0;39m [2m:[0;39m HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
[2m2021-12-13 23:06:05.150[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.h.e.t.j.p.i.JtaPlatformInitiator [0;39m [2m:[0;39m HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
[2m2021-12-13 23:06:05.156[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'default'
[2m2021-12-13 23:06:05.324[0;39m [33m WARN[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mJpaBaseConfiguration$JpaWebConfiguration[0;39m [2m:[0;39m spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
[2m2021-12-13 23:06:05.512[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.b.d.a.OptionalLiveReloadServer [0;39m [2m:[0;39m LiveReload server is running on port 35729
[2m2021-12-13 23:06:05.605[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http) with context path ''
[2m2021-12-13 23:06:05.612[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36mn.j.springboot.StockApplication [0;39m [2m:[0;39m Started StockApplication in 2.323 seconds (JVM running for 3.142)
[2m2021-12-13 23:06:19.900[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring DispatcherServlet 'dispatcherServlet'
[2m2021-12-13 23:06:19.900[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Initializing Servlet 'dispatcherServlet'
[2m2021-12-13 23:06:19.901[0;39m [32m INFO[0;39m [35m19252[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet [0;39m [2m:[0;39m Completed initialization in 1 ms
[2m2021-12-13 23:06:19.954[0;39m [31mERROR[0;39m [35m19252[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet] [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.Error: Unresolved compilation problem:
The method save(S) in the type CrudRepository<Fournisseur,Long> is not applicable for the arguments (Fournisseur)
] with root cause
java.lang.Error: Unresolved compilation problem:
The method save(S) in the type CrudRepository<Fournisseur,Long> is not applicable for the arguments (Fournisseur)
at net.javaguides.springboot.controller.FournisseurController.createFournisseur(FournisseurController.java:33) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.13.jar:5.3.13]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.13.jar:5.3.13]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.13.jar:5.3.13]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.55.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.13.jar:5.3.13]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.55.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.55.jar:9.0.55]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.13.jar:5.3.13]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.13.jar:5.3.13]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.13.jar:5.3.13]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.13.jar:5.3.13]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.13.jar:5.3.13]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.13.jar:5.3.13]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
In the video am following for this example the same code worked. I did some researches and it is possible to create a custom save method, i tried it but always got the same result, in addition it is not recommended to do so. Is there any issue with my class??
I just changed the controller create fournisseur by:
//Create Fournisseur
#PostMapping("/fournisseurs")
public net.javaguides.springboot.model.Fournisseur createFournisseur(#RequestBody net.javaguides.springboot.model.Fournisseur fournisseur){
#SuppressWarnings("unused")
net.javaguides.springboot.model.Fournisseur updateFournisseur = fournisseurRepository.save(fournisseur);
return fournisseurRepository.save(fournisseur);
}
and it works :D

Spring SecurityConfig not working

I have played with this for some time, but it does not seem to get wired to my project.
Here is the file from the last time I edited it. I have permit all so I can test to see if this file is working or not. I am still getting 401 error when I don't include any authentication.
Any idea what I am missing?
package org.springframework.security.samples.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
#Configuration
#EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
#Autowired
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
}
EDIT
Here are security debug logs when I start the application
2016-12-07 23:24:48.673 DEBUG 15640 --- [ main] eGlobalAuthenticationAutowiredConfigurer : Eagerly initializing {org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration=org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$$EnhancerBySpringCGLIB$$60c02dff#68fc9167}
2016-12-07 23:24:48.827 DEBUG 15640 --- [ main] edFilterInvocationSecurityMetadataSource : Adding web access control expression 'hasAnyRole('ROLE_USER')', for org.springframework.security.web.util.matcher.AnyRequestMatcher#1
2016-12-07 23:24:48.834 DEBUG 15640 --- [ main] o.s.s.w.a.i.FilterSecurityInterceptor : Validated configuration attributes
2016-12-07 23:24:48.835 DEBUG 15640 --- [ main] o.s.s.w.a.i.FilterSecurityInterceptor : Validated configuration attributes
Here are the security debug logs when I make the rest call
2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/css/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/js/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/images/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/webjars/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/**/favicon.ico'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/error'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/**']
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request '/users' matched by universal pattern '/**'
[2m2016-12-07 23:29:19.114[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m matched
[2m2016-12-07 23:29:19.115[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
[2m2016-12-07 23:29:19.116[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
[2m2016-12-07 23:29:19.118[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter'
[2m2016-12-07 23:29:19.119[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter'
[2m2016-12-07 23:29:19.119[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', GET]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'POST /users' doesn't match 'GET /logout
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', POST]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Checking match of request : '/users'; against '/logout'
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', PUT]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'POST /users' doesn't match 'PUT /logout
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m Trying to match using Ant [pattern='/logout', DELETE]
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.u.matcher.AntPathRequestMatcher [0;39m [2m:[0;39m Request 'POST /users' doesn't match 'DELETE /logout
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.web.util.matcher.OrRequestMatcher [0;39m [2m:[0;39m No matches found
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 5 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
[2m2016-12-07 23:29:19.120[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
[2m2016-12-07 23:29:19.121[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.AnonymousAuthenticationFilter [0;39m [2m:[0;39m Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken#9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails#957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
[2m2016-12-07 23:29:19.123[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.security.web.FilterChainProxy [0;39m [2m:[0;39m /users at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
[2m2016-12-07 23:29:19.124[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.i.FilterSecurityInterceptor [0;39m [2m:[0;39m Secure object: FilterInvocation: URL: /users; Attributes: [hasAnyRole('ROLE_USER')]
[2m2016-12-07 23:29:19.124[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.i.FilterSecurityInterceptor [0;39m [2m:[0;39m Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken#9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails#957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS
[2m2016-12-07 23:29:19.128[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.access.vote.AffirmativeBased [0;39m [2m:[0;39m Voter: org.springframework.security.web.access.expression.WebExpressionVoter#6175291d, returned: -1
[2m2016-12-07 23:29:19.134[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.ExceptionTranslationFilter [0;39m [2m:[0;39m Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84) ~[spring-security-core-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233) ~[spring-security-core-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) ~[spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:121) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) [spring-security-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.6.jar:8.5.6]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_112]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_112]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.6.jar:8.5.6]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_112]
[2m2016-12-07 23:29:19.135[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.a.ExceptionTranslationFilter [0;39m [2m:[0;39m Calling Authentication entry point.
[2m2016-12-07 23:29:19.135[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36mo.s.s.w.header.writers.HstsHeaderWriter [0;39m [2m:[0;39m Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher#5e6187fd
[2m2016-12-07 23:29:19.135[0;39m [32mDEBUG[0;39m [35m15640[0;39m [2m---[0;39m [2m[nio-8080-exec-1][0;39m [36ms.s.w.c.SecurityContextPersistenceFilter[0;39m [2m:[0;39m SecurityContextHolder now cleared, as request processing completed
Probably I'm missing something. I don't know why you're using #EnableWebMvcSecurity with Spring Boot, it is deprecated, but that's not the point.
If you're using Spring Boot and want to create a security config that allow every call you can do it like this:
#EnableWebSecurity
#Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
}
You didn't disable the default security configuration, so Spring Boot uses the default security configuration, see Spring Boot Reference Guide:
The default security configuration is implemented in SecurityAutoConfiguration and in the classes imported from there (SpringBootWebSecurityConfiguration for web security and AuthenticationManagerConfiguration for authentication configuration which is also relevant in non-web applications). To switch off the default web application security configuration completely you can add a bean with #EnableWebSecurity (this does not disable the authentication manager configuration or Actuator’s security). To customize it you normally use external properties and beans of type WebSecurityConfigurerAdapter (e.g. to add form-based login). To also switch off the authentication manager configuration you can add a bean of type AuthenticationManager, or else configure the global AuthenticationManager by autowiring an AuthenticationManagerBuilder into a method in one of your #Configuration classes. There are several secure applications in the Spring Boot samples to get you started with common use cases.
The basic features you get out of the box in a web application are:
An AuthenticationManager bean with in-memory store and a single user (see SecurityProperties.User for the properties of the user).
Ignored (insecure) paths for common static resource locations (/css/**, /js/**, /images/**, /webjars/** and **/favicon.ico).
HTTP Basic security for all other endpoints.
Security events published to Spring’s ApplicationEventPublisher (successful and unsuccessful authentication and access denied).
Common low-level features (HSTS, XSS, CSRF, caching) provided by Spring Security are on by default.
All of the above can be switched on and off or modified using external properties (security.*). To override the access rules without changing any other auto-configured features add a #Bean of type WebSecurityConfigurerAdapter with #Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) and configure it to meet your needs.
See also spring-boot-sample-web-secure:
#Configuration
#Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin()
.loginPage("/login").failureUrl("/login?error").permitAll().and()
.logout().permitAll();
}
#Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("admin")
.roles("ADMIN", "USER").and().withUser("user").password("user")
.roles("USER");
}
}
Try to ignore it at all:
#Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/**");
}

Spring Boot ClassCastException on composite micro service, after some time - OK

I have strange behavior of my composite microservice (API gateway) of 2 microservices. On first HTTP request it returns the ClassCastException, but after some time it returns normal JSON. How can I set the application to return normal JSON right on the first HTTP request?
Configuration for all 3 services is similar: spring.application.name, server port, Eureka registration address.
There are 2 microservices: car-service (annotated with #Controller) and truck-service (annotated with #RestController), the methods which return List<Car> and List<Truck> are correspondingly:
#HystrixCommand(commandKey = "getCars", groupKey = "Cars")
#RequestMapping(value = "/cars", method = RequestMethod.GET)
public List<Car> getCars() {
return carService.getAllCars();
}
and
#ResponseBody
#RequestMapping(value = "/trucks", method = RequestMethod.GET)
public List<Truck> getTrucks() {
return truckService.getAllTrucks();
}
(setting both services to #Controller or #RestController doesn't affect the behavior)
Composite Vehicle service has 2 interfaces injected with #FeignClient annotation and returns composite object VehicleSummary which has List<Car> and List<Truck> fields with standard getters and setters:
#Component
public class VehicleService {
#Inject
private CarClient carClient;
#Inject
private TruckClient truckClient;
public VehicleSummary getAllVehicles() {
List<Car> cars = carClient.getAllCars();
List<Truck> trucks = truckClient.getTrucks();
VehicleSummary summary = new VehicleSummary();
summary.setCars(cars);
summary.setTrucks(trucks);
return summary;
}
}
The full source code is available at https://github.com/t3rmin41/simple-microservices-app
The stacktrace of the exception is below :
2015-12-21 21:17:00.560 INFO 26207 --- [nio-8883-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2015-12-21 21:17:00.560 INFO 26207 --- [nio-8883-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2015-12-21 21:17:00.612 INFO 26207 --- [nio-8883-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 52 ms
2015-12-21 21:17:00.967 INFO 26207 --- [trix-Vehicles-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#31eb7d: startup date [Mon Dec 21 21:17:00 EET 2015]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#2db9fb
2015-12-21 21:17:01.020 INFO 26207 --- [trix-Vehicles-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2015-12-21 21:17:01.383 INFO 26207 --- [trix-Vehicles-1] c.netflix.config.ChainedDynamicProperty : Flipping property: car-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2015-12-21 21:17:01.525 INFO 26207 --- [trix-Vehicles-1] c.netflix.loadbalancer.BaseLoadBalancer : Client:car-service instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=car-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2015-12-21 21:17:01.593 INFO 26207 --- [trix-Vehicles-1] c.netflix.config.ChainedDynamicProperty : Flipping property: car-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2015-12-21 21:17:01.600 INFO 26207 --- [trix-Vehicles-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client car-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=car-service,current list of Servers=[nikzgs-Latitude-E5420:8881],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:nikzgs-Latitude-E5420:8881; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 03:00:00 EET 1970; First connection made: Thu Jan 01 03:00:00 EET 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0;stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList#a14ec6
2015-12-21 21:17:02.054 ERROR 26207 --- [nio-8883-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: java.lang.String cannot be cast to my.vehicle.entity.VehicleSummary] with root cause
java.lang.ClassCastException: java.lang.String cannot be cast to my.vehicle.entity.VehicleSummary
at my.simple.vehicle.VehicleController$$EnhancerBySpringCGLIB$$3b97a077.getAllVehicles(<generated>) ~[composite-vehicle-service-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:242) ~[spring-boot-actuator-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:111) ~[spring-boot-actuator-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) ~[spring-boot-actuator-1.3.0.RELEASE.jar!/:1.3.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar!/:4.2.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) ~[tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.28.jar!/:8.0.28]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
2015-12-21 21:17:02.535 INFO 26207 --- [ool-10-thread-1] c.netflix.config.ChainedDynamicProperty : Flipping property: car-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2015-12-21 21:17:07.778 INFO 26207 --- [pool-6-thread-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_VEHICLE-SERVICE/nikzgs-Latitude-E5420 - Re-registering apps/VEHICLE-SERVICE
2015-12-21 21:17:07.778 INFO 26207 --- [pool-6-thread-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_VEHICLE-SERVICE/nikzgs-Latitude-E5420: registering service...
2015-12-21 21:17:07.791 INFO 26207 --- [pool-6-thread-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_VEHICLE-SERVICE/nikzgs-Latitude-E5420 - registration status: 204
The problem was caused by VehicleController class methods:
#ResponseBody
#HystrixCommand(commandKey = "getAllVehicles", groupKey = "Vehicles", fallbackMethod = "returnErrorMessage")
#RequestMapping(value = "/vehicles", method = RequestMethod.GET)
public VehicleSummary getAllVehicles() {
return vehicleService.getAllVehicles();
}
#HystrixCommand
private String returnErrorMessage() {
return "Fallback error message";
}
The problem was that Hystrix is trying to construct the response with returnErrorMessage() method which returns String and getAllVehicles() returns VehicleSummary class. Hence, it cannot cast String to VehicleSummary.
The correct way is to return the same class on the fallback:
#ResponseBody
#HystrixCommand(commandKey = "getAllVehicles", groupKey = "Vehicles", fallbackMethod = "returnErrorMessage")
#RequestMapping(value = "/vehicles", method = RequestMethod.GET)
public VehicleSummary getAllVehicles() {
return vehicleService.getAllVehicles();
}
#HystrixCommand
private VehicleSummary returnErrorMessage() {
return new VehicleSummary();
}

Resources