Spring Boot java.lang.NoClassDefFoundError: javax/servlet/Filter

for the maven users, comment the scope provided in the following dependency: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!–<scope>provided</scope>–> </dependency> UPDATE As feed.me mentioned you have to uncomment the provided part depending on what kind of app you are deploying. Here is a useful link with the details: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-maven-packaging

How to Solve 403 Error in Spring Boot Post Request

you have to disable csrf Protection because it is enabled by default in spring security: here you can see code that allow cors origin. import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception{ http.cors().and().csrf().disable(); } @Bean CorsConfigurationSource … Read more

Spring Boot Microservices – Spring Security – ServiceTest and ControllerTest for JUnit throwing java.lang.StackOverflowError

The error is most likely caused by declaring the AuthenticationManager as a @Bean. Try this in your test class: @MockBean private AuthenticationManager _authenticationManager; That said, the Spring Security team does not recommend exposing the AuthenticationManager in this way, see the comment in Spring issue #29215

Disabling a filter for only a few paths

In your custom AuthenticationFilter you can define a RequestMatcher and use it before doing your logic, like so: public class AuthenticationFilter extends OncePerRequestFilter { private final RequestMatcher ignoredPaths = new AntPathRequestMatcher(“/swagger-ui”); @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) { if (this.ignoredPaths.matches(request)) { filterChain.doFilter(request, response); return; } // do your logic filterChain.doFilter(request, response); } … Read more

Spring Boot JSF Integration

This is the way I have JSF working with Spring Boot (full sample project at Github, updated with JSF 2.3 and Spring Boot 2): 1. Dependencies In addition to the standard web starter dependency, you’ll need to include the tomcat embedded jasper marked as provided (thanks @Fencer for commenting in here). Otherwise you’ll get an … Read more

Spring boot controller content negotiation

You can use ContentNegotiationConfigurer Firstly, you should override the configureContentNegotiation method in your configuration class: @Configuration @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false). favorParameter(true). defaultContentType(MediaType.APPLICATION_JSON). mediaType(“xml”, MediaType.APPLICATION_XML); } } favorParameter(true) – enabling favoring path expressions over parameter or accept headers. defaultContentType(MediaType.APPLICATION_JSON) – sets the default content type. this … Read more

One Spring Boot project, deploy to both JAR or WAR

I managed to do it by adding <packaging>${packaging.type}</packaging> to the POM file and then setting different profiles for JAR and WAR: <profiles> <profile> <id>jar</id> <properties> <packaging.type>jar</packaging.type> </properties> </profile> <profile> <id>war</id> <properties> <packaging.type>war</packaging.type> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> </profile> </profiles> Now mvn package -P war produces a WAR and mvn package -P jar … Read more