如何解决 javax.servlet.ServletException: 基本 Spring Security 的圆形视图路径?

问题描述

我是 Spring Boot 的新手,并试图为我的 Spring Boot 控制器中的单个端点实现基本的 Spring Security。但我不知道如何解决圆形视图错误

我的控制器

@Controller
@RequestMapping("/api")
public class HelloSecurityController {
    
    @RequestMapping({"/hello"})
    public static String helloWorld() {
        return "hello";
    }

我的安全配置器

@EnableWebSecurity
public class SecurityConfigurer extends WebSecurityConfigurerAdapter {
    
    @Autowired
    private MyUserDetailsService myUserDetailsService;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(myUserDetailsService);

    
    }
    
    @Bean
    public PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }
    ```


MyUserDetailsS​​ervice 返回一个带密码的简单用户

@Service
public class MyUserDetailsService implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {

        return new User("foo","foo",new ArrayList<>());

我在初始化 Spring Boot 项目时保留在 maven pom 文件中的依赖

<dependencies>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

我的项目的包结构: proj_struct

在 spring security 生成登录表单页面使用用户名和密码登录后,我收到错误: javax.servlet.servletexception: 循环视图路径 [hello]: 将再次分派回当前处理程序 URL [/api/hello]。检查您的 ViewResolver 设置! (提示:由于认视图名称生成,这可能是未指定视图的结果。)

我没有在模板文件夹中保留任何静态模板 (HTML/JSP)。我不知道我是否必须在登录后看到一个简单的字符串。我该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)