2017-02-12 69 views
1
import org.springframework.boot.*; 
import org.springframework.boot.autoconfigure.*; 
import org.springframework.web.bind.annotation.*; 

@RestController 
@SpringBootApplication 
public class Example { 

    @RequestMapping("/") 
    String home() { 
     return "Hello World!"; 
    } 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(Example.class, args); 
    } 

} 

我只用这种依赖性:https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web/1.4.4.RELEASE禁止在春季启动Hello World应用程序的所有模块

我不需要任何过滤器,任何的安全,我想,经过春收到的请求,并检查路由,它会调用首页方法。

如何配置Spring Boot以禁用所有过滤器,所有安全性,所有东西?

+2

通过不包括的依赖关系。 –

+0

请分享您正在使用的pom.xml –

+0

@ M.Deinum我只有一个依赖关系,并且过滤器无论如何都被执行 – Romper

回答

0

可以使用security.ignored属性,也可以接受使用此配置(春季启动1.4.2)的所有请求:

import org.springframework.context.annotation.Configuration; 
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; 

@Configuration 
@EnableWebSecurity 
public class UnsafeWebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(final HttpSecurity http) throws Exception { 
     // Accept all requests and disable CSRF 
     http.csrf().disable() 
      .authorizeRequests() 
      .anyRequest().permitAll(); 

     // To be able to see H2 console. 
     http.headers().frameOptions().disable(); 
    } 

}