【问题标题】:Disable all modules in Spring Boot hello world application禁用 Spring Boot hello world 应用程序中的所有模块
【发布时间】:2017-06-30 11:50:02
【问题描述】:
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

我不需要任何过滤器,任何安全性,我希望在 Spring 收到请求并检查路由后,它会调用 home 方法。

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

【问题讨论】:

  • 不包括依赖项。
  • 请分享您正在使用的 pom.xml
  • @M.Deinum 我只有一个依赖项,无论如何都会执行过滤器
  • @RavindraDevadiga 我添加了依赖项
  • 如果这是唯一的依赖就没有安全性...

标签: java spring spring-mvc spring-boot


【解决方案1】:

您可以使用security.ignored 属性,也可以使用此配置接受所有请求(spring boot 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();
    }

}

【讨论】:

    猜你喜欢
    • 2018-02-02
    • 2014-10-31
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多