我有一个带弹簧靴的单页角度应用程序.它看起来如下
src
main
java
controller
HomeController
CustomerController
OtherController
webapp
js/angular-files.js
index.html
Run Code Online (Sandbox Code Playgroud)
Spring启动正确默认为webapp文件夹并提供index.html文件.
我要做的是
1) 对于每个本地REST请求,不以/ api覆盖开头并重定向到默认的webapp/index.html.我打算为弹簧控制器提供任何/ api服务.
2)有没有办法为所有控制器添加api前缀,这样我就不必每次都写api.
例如
@RequestMapping("/api/home") can write shorthand in code @RequestMapping("/home")
Run Code Online (Sandbox Code Playgroud)
要么
@RequestMapping("/api/other-controller/:id") can write shorthand @RequestMapping("/other-controller/:id")
Run Code Online (Sandbox Code Playgroud)
编辑.. 更多注释以上解释更好
我正在寻找每个api请求,例如1) http:// localhost:8080/api/home使用api保持api并解决纠正控制器并返回json.
但是,如果有人输入URL,如http:/// localhost/some-url 或http:/// localhost/some-other/123/url 那么它将提供index.html页面并保留URL.
替代方法 - 尝试添加#ErrorViewResolver Springboot/Angular2 - 如何处理HTML5网址?
我有整个前端部分在资源中铺设的应用程序.我想将事情分开.并且具有用于UI的单独服务器,例如由gulp提供.
因此,我假设我的服务器应该返回index.html客户端呈现的所有请求.
例如:我有'user /:id'路由,它通过角度路由进行管理,不需要任何服务器.如何配置以便服务器不会重新加载或重定向到任何地方?
我的安全配置正在跟随(不知道它是否负责此类事情):
public class Application extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**", "/app/**", "/app.js")
.permitAll().anyRequest().authenticated().and().exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
.logoutSuccessUrl("/").permitAll().and().csrf()
.csrfTokenRepository(csrfTokenRepository()).and()
.addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
}
Run Code Online (Sandbox Code Playgroud)