我正在尝试创建一个基本的springboot rest服务,当您访问“ / hello”时返回“ hi”。我已经配置了安全性,以便使用.permitAll()允许所有请求,如下所示:
WebSecurityConfiguration.java
@EnableWebSecurity
public class WebSecurityConfiguration implements HttpSecurityConfigurer {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**")
.permitAll();
}
}
我还有一个控制器类,其中指定了一个路径:
HelloController.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHi(){
return "Hi";
}
}
我的项目结构如下:
com.test.project.rest.testservice
>TestServiceApplication.java
com.test.project.rest.testservice.config
>WebSecurityConfiguration.java
com.test.project.rest.testservice.controller
>HelloController.java
由于某种原因,所有路径仅显示404-找不到,即使其在控制器中指定还是未指定。可能是什么原因引起的?
这些是我正在使用的安全性依赖项:
<!-- org.springframework.security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>