如何解决javax.servlet.servletexception:基本Spring Security 的循环视图路径?

nhjlsmyf  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(294)

我是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();
    }
    ```

MyUserDetails服务,返回一个带有密码的简单用户

@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设置(提示:这可能是由于生成默认视图名称而导致的未指定视图。)
我没有在templates文件夹中保留任何静态模板(html/jsp)。我不知道登录后是否必须这样做,我只想看到一个简单的字符串。我如何解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题