-1
Spring Boot
とAngular 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
クラスに追加
:
@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'.
。誰か他に何ができるのか?通常、手動でリソースハンドラを設定する必要はありません春のブートを使用する場合
そして、あなたはあなたのケースのようにカスタムの場所を提供したい場合は、あなたのハンドラでこれを含める: .addResourceHandler(「/リソース/ **」) – joseph
は、だから私はに変更: '@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)。 メッセージがありません。 ' –
私はあなたのURLに#記号を使用することはできません。 – joseph