Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何覆盖默认的Spring引导登录页面?_Spring Boot - Fatal编程技术网

Spring boot 如何覆盖默认的Spring引导登录页面?

Spring boot 如何覆盖默认的Spring引导登录页面?,spring-boot,Spring Boot,我是全新的SpringBoot2,我有一个简单的应用程序,我正在尝试运行。不幸的是,每次我运行我的服务时,我都会从Spring Boot得到这个登录表单。有什么办法可以推翻这个吗 我已经尝试过这个问题的解决方案,但它对我不起作用: 以下是迄今为止我对代码的了解: import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; impo

我是全新的SpringBoot2,我有一个简单的应用程序,我正在尝试运行。不幸的是,每次我运行我的服务时,我都会从Spring Boot得到这个登录表单。有什么办法可以推翻这个吗

我已经尝试过这个问题的解决方案,但它对我不起作用:

以下是迄今为止我对代码的了解:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Defines the application, supports service registry, circuit breaker 
 * for Spring Boot application.
 * 
 * @EnableJpaRepositories - add this to enable 
 * 
 * @author himanshu sharma
 * @since June 2017
 */
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableSwagger2
@EnableCaching
@SpringBootApplication
@ImportResource("classpath:service-config.xml")
@ComponentScan(basePackages = "com.manulife.ap.*, io.swagger")
public class Application{
    @Autowired
    DiscoveryClient discoveryClient;

    /**
     * Application start point.
     * @param args
     */
    public static void main(String[] args){
        SpringApplication.run(Application.class, args);     
    }

    @RequestMapping(value="/greeting", method=RequestMethod.GET)
    public String sayHello () {
        return "Hello from Spring Boot!";
    }
}
-编辑:@devshawn- 我尝试了排除SecurityAutoConfiguration.class的解决方案,但当我尝试访问我的端点时,不知何故收到了以下错误消息:


我假设您使用的是SpringBoot2,因为您没有提到您使用的是哪个版本的Spring。在spring boot 2中,您不能像在spring boot 1中那样通过属性文件禁用默认登录。有几种方法可以做到这一点,这取决于你想要达到的目标

允许所有访问,稍后保护端点 添加一个名为SecurityConfig的类,如下所示:

@配置 公共类SecurityConfig扩展了WebSecurity配置适配器{ @凌驾 受保护的void configureHttpSecurity http引发异常{ http.authorizeRequests.antMatchers/**.permitAll; } } 这将删除服务中所有端点上的身份验证。稍后,您可以通过此类进一步配置安全性

删除安全自动配置 当在类路径上找到Spring安全性时,Spring Boot会自动配置安全性。如果您不想通过更改@SpringBootApplication注释自动配置它,可以将其全部删除

@SpringBootApplicationexclude={SecurityAutoConfiguration.class}
嗨,谢谢你的解决方案,我两个都试过了。然而,当我尝试localhost:8080/greeting时,第一个仍然将我重定向到localhost:8080/login。至于第二个,我将编辑我的帖子并粘贴一张图片。对于这个版本,我尝试在命令行上运行spring-version,得到了springcliv2.1.3.RELEASE。你问的是这个版本吗?@Uzi-就是这个版本,是的!因此,RequestMappings只在用@RestController注释的类上工作。将它添加到您的文件中,它就会开始工作。第一个不起作用可能是因为组件扫描没有捕捉到您新创建的配置文件。真糟糕,我添加@RestController的那一刻起作用了。谢谢你的帮助。我将在我的问题中添加这个版本,以防将来有人会使用它。再次感谢。祝你幸福长寿