2017-08-04 6 views
0

私はSpring Bootを初めて使用しており、以前のプロジェクトにSpring Securityモジュールを追加したいと考えています。私はこれに続いたlink。私のSpring Bootバージョンは1.5.6.RELEASEです。ここでjavax.servlet.ServletException:円形ビューパス[ログイン]

セキュリティ設定

@Configuration 
@EnableWebSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 
    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
       .antMatchers("/", "/home").permitAll() 
       .anyRequest().authenticated() 
       .and() 
      .formLogin() 
       .loginPage("/login") 
       .permitAll() 
       .and() 
      .logout() 
       .permitAll(); 
    } 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth 
      .inMemoryAuthentication() 
      .withUser("user").password("password").roles("USER"); 
    } 
} 

はここでMVCの設定です:

@Configuration 
public class MvcConfig extends WebMvcConfigurerAdapter { 

    @Override 
    public void addViewControllers(ViewControllerRegistry registry) { 
     registry.addViewController("/home").setViewName("home"); 
     registry.addViewController("/").setViewName("home"); 
     registry.addViewController("/hello").setViewName("hello"); 
     registry.addViewController("/login").setViewName("login"); 
    } 

私はhome.htmlhello.htmllogin.htmlresources/templates/に配置されていることを確認することができます。私は以前のプロジェクトに春のセキュリティ部分を追加したとして、私はまた、JPA要求

@Controller 
@RequestMapping("/test/pgsql") 
public class TestPostgreSQLController { 

    @Autowired 
    private CustomerRepository customerRepository; 

    @RequestMapping("/save") 
    public @ResponseBody 
    String process() { 
     customerRepository.save(new Customer("Neo", "Chan")); 
     customerRepository.save(new Customer("Luke", "Liu")); 
     customerRepository.save(new Customer("Ran", "Guo")); 
     customerRepository.save(new Customer("Joey", "Chen")); 
     customerRepository.save(new Customer("Larry", "Huang")); 
     return "Done"; 
    } 

    @RequestMapping("/findbyid") 
    public @ResponseBody String findById(@RequestParam("id") long id) { 
     String result = ""; 
     result = customerRepository.findOne(id).toString(); 
     return result; 
    } 

    @RequestMapping("/find") 
    public @ResponseBody String find(@RequestParam("lastname") String lastName) { 
     String results = ""; 
     for (Customer bauer : customerRepository.findCustomersByLastName(lastName)) { 
      System.out.println(bauer.toString()); 
      results = results + bauer.toString() + "<br>"; 
     } 
     return results; 
    } 


} 

を扱うコントローラがあるのpom.xmlがこの

<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.postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 

のようなものです私はジャーパッケージとしてプロジェクトをビルドします。私がlocalhost:8080/homeまたはlocalhost:8080/loginアドレスにアクセスしたとき。次の例外をスローします。

javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.) 

いずれかの提案がありますか?前もって感謝します。

答えて

0

それはそれは1

役に立てば幸い私のために働くこと registry.addViewController("/login").setViewName("login.html"); を追加する]この質問は、質問されたが、私はここで答えを見つけた後 試し長い時間です