Java Spring引导Rest响应返回login.jsp

Java Spring引导Rest响应返回login.jsp,java,spring,spring-boot,spring-mvc,spring-security,Java,Spring,Spring Boot,Spring Mvc,Spring Security,我在学春靴。我用Spring-Boot-security创建了一个示例Spring-Boot-Web应用程序,它工作得很好。现在我想在同一个Web应用程序中添加Rest-Webservices功能。 问题: 当我试图访问任何API时,我会得到login.jsp作为响应。 要求:我希望不需要JSON响应身份验证和授权。 要实现这一目标,我需要做哪些改变。 网站安全配置: @配置 @启用Web安全性 公共类WebSecurityConfig扩展了WebSecurityConfigureAdapter

我在学春靴。我用Spring-Boot-security创建了一个示例Spring-Boot-Web应用程序,它工作得很好。
现在我想在同一个Web应用程序中添加Rest-Webservices功能。

问题: 当我试图访问任何API时,我会得到login.jsp作为响应。
要求:我希望不需要JSON响应身份验证和授权。
要实现这一目标,我需要做哪些改变。


网站安全配置:

@配置
@启用Web安全性
公共类WebSecurityConfig扩展了WebSecurityConfigureAdapter{ @限定符(“userDetailsServiceImpl”)
@自动连线
私有用户详细信息服务用户详细信息服务; @豆子 公共BCryptPasswordEncoder BCryptPasswordEncoder(){ 返回新的BCryptPasswordEncoder(); } @凌驾 受保护的无效配置(HttpSecurity http)引发异常{ http .授权请求() .antMatchers(“/resources/**,“/registration”).permitAll() .anyRequest().authenticated() .及() .formLogin() .login页面(“/login”) .permitAll() .及() .logout() .permitAll(); } @豆子 public AuthenticationManager customAuthenticationManager()引发异常{ 返回authenticationManager(); } @自动连线 public void configureGlobal(AuthenticationManagerBuilder auth)引发异常{ auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder()); } }
将该路径添加到
antMatchers
到permitAll

antMatchers(“/resources/**”、“/registration”、“/api/user/**”)。permitAll()


这将禁用该URL的安全性

您在表单中调用的URL是什么postI am使用邮递员URI进行测试:那是什么uri@Dickens我正在使用Postman URI进行测试:“这里的'admin'是PathVariable”请为
/jobseers/api/user/admin
发布请求映射代码,我怀疑yuo正在使用Spring MVC,并在web.xml和applicationcontext.xml中使用JSP视图映射
@Configuration  
@EnableWebSecurity <br>
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Qualifier("userDetailsServiceImpl") <br>
    @Autowired <br>
    private UserDetailsService userDetailsService;

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/resources/**", "/registration").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Bean
    public AuthenticationManager customAuthenticationManager() throws Exception {
        return authenticationManager();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
    }
}