2017-11-14 1 views
-1

Spring BootAngular 4の組み合わせでアプリケーションを実装しました。実装のセキュリティの違いは同じエラーで終了する

@Configuration 
@EnableWebMvc 
@ComponentScan("com.inventory") 
public class WebConfig extends WebMvcConfigurerAdapter { 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     registry.addResourceHandler("/resources/static/**") 
       .addResourceLocations("classpath:/resources/static/"); 
    } 

    @Override 
    public void addViewControllers(ViewControllerRegistry registry) { 
     registry.addViewController("/").setViewName("index.html"); 
    } 
} 

と::その後、私はSpring Securityクラスに追加

static directory

@Configuration 
@EnableWebSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private UserDetailsService userDetailsService; 

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

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.csrf().disable().authorizeRequests() 
       .antMatchers("/").permitAll() 
       .anyRequest().authenticated(); 
    } 

、何もかもが働くべきだと思える私は/resources/staticディレクトリの下にあるすべてのAngularファイルを置きます。私は私のアプリを実行するたびに残念ながら、それは例外をスロー:

@Controller 
public class ViewController { 

    @RequestMapping(value = "/#/") 
    public String index() { 
     return "forward:/index.html"; 
    } 

    @RequestMapping(value = "/") 
    public String home() { 
     return "forward:/index.html"; 
    } 
} 

しかし、何も動作します。私はこれを追加するように切り抜いたソリューションを試してみました。もちろん

There was an unexpected error (type=Internal Server Error, status=500). 
Could not resolve view with name 'index.html' in servlet with name 'dispatcherServlet'. 

。誰か他に何ができるのか?通常、手動でリソースハンドラを設定する必要はありません春のブートを使用する場合

答えて

0

、春ブーツは、自動的に次のLOCから内容をロードします:

  • /静的
  • /公共
  • /リソース
  • /META-INF /リソース

spring boot guides on loading static contents

01を参照してください
+0

そして、あなたはあなたのケースのようにカスタムの場所を提供したい場合は、あなたのハンドラでこれを含める: .addResourceHandler(「/リソース/ **」) – joseph

+0

は、だから私はに変更: '@Override ます。public void addResourceHandlers(ResourceHandlerRegistryレジストリ){ registry.addResourceHandler( "/ resources/**"、 "/"、 "/#/").addResourceLocations("/resources/static/index.html",/resources/static/index.html" "/resources/static/index.html"); } 'それはスローする'予期しないエラーがあった(type = Not Found、status = 404)。 メッセージがありません。 ' –

+0

私はあなたのURLに#記号を使用することはできません。 – joseph

関連する問題