我使用了spring 2.1.6 security,并在pom.xml中添加了spring安全性。我的pom.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rest.restfulwebservices</groupId>
<artifactId>restfulwebservices</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>restfulwebservices</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- for getting data in xml format-->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>在application.properties文件中,我添加了一些代码来禁用spring安全:
security.ignored=/**
spring.security.enabled=false
management.security.enabled=false
security.basic.enabled=false我的装货课是:
package com.rest.restfulwebservices.restfulwebservices;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.util.Locale;
@SpringBootApplication(scanBasePackages = {"com.rest"})
public class RestfulwebservicesApplication {
public static void main(String[] args) {
SpringApplication.run(RestfulwebservicesApplication.class, args);
}
}虽然我添加了该配置以禁用spring安全性,但它仍然将我默认生成的密码显示为:
Using generated security password: c23282bc-9b85-4fc4-a947-81a5f668a751为什么弹簧安全的禁用不起作用?
发布于 2019-08-06 15:49:40
Spring 2中不推荐使用security.ignored=/**。使用antMatchers("/**").permitAll();允许所有请求,或者如果您不想使用Security,只需删除依赖项
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{
http.authorizeRequests().antMatchers("/**").permitAll();
}
}https://stackoverflow.com/questions/57379452
复制相似问题