我用spring boot启动我的web应用程序.它使用一个简单的主类来启动嵌入式tomcat服务器:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我想以他能够处理将被激活的angularjs html5mode的方式配置服务器
$locationProvider.html5Mode(true);
Run Code Online (Sandbox Code Playgroud)
来自其他用户的相关帖子显示您需要重定向到根目录.html5模式从url中删除hashbag.如果刷新页面,服务器找不到页面导致他不处理哈希.请参阅:AngularJS - 为什么在更改URL地址时$ routeProvider似乎不起作用,我收到404错误
我有一个带弹簧靴的单页角度应用程序.它看起来如下
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网址?
我有一个Angular 4(ES6)应用程序,我想从Spring Boot应用程序提供服务.我的Angular应用程序有一个index.html,当http:// localhost:8080的地址被命中时,Spring Boot知道要映射到在Angular中映射到"/ search"的index.html文件.
但是,我有另一条名为"adminlogin"的路线,我将通过该途径访问
但在这个例子中,它命中了我的Spring Boot应用程序,它没有映射,然后抛出错误.
如何获取http:// localhost:8080/adminLogin的地址转到我的Angular应用程序?
我已经构建了一个包括 Angluar5 的 Springboot 应用程序。我有一个 gradle 构建脚本,它将角度文件加载到我的 springboot 项目中。这些文件位于我的 springboot 项目的资源/静态下。当我启动我的应用程序时,angular 的路由不再起作用,我得到
错误:无法匹配任何路由。URL 段:'访问'
我的项目结构:
我使用以下语句部署了我的 angular 应用程序:
ng build --deploy-url=BeatAcknowledgeTest --op=../backend/src/main/resources/static
这将使我的静态文件可以通过以下链接访问:
www.mySite.com/BeatAcknowledgeTest/...
如果我输入
www.mySite.com/BeatAcknowledgeTest/access
页面呈现,一切都很好,但是当我在另一个组件中时,例如
www.mySite.com/BeatAcknowledgeTest/home
然后我点击一个按钮,将我路由到
www.mySite.com/BeatAcknowledgeTest/access
我收到一个错误,我的应用程序没有重定向。
有什么建议?
我在本教程之后成功地将我的Angular2应用程序与Spring Boot后端集成,将已编译的JS资源放到/ ui子目录中.基本上一切正常,Angular2应用程序可以通过appname/ui URL访问.
但是,我想知道是否有办法告诉Spring'传递' / ui路径的子网,因为当前Spring拦截了每个请求目标/ ui/*,阻止Angular2路由器正确导航到/ ui路径下的资源.
目前,我只在我的一个控制器中有这个映射:
@RequestMapping(value = "/ui")
public String uiIndex() {
return "/ui/index.html";
}
Run Code Online (Sandbox Code Playgroud)
有了这个,接口正确地显示在/ ui,但是当我直接从浏览器中解决它时,Spring会向我发送错误和404 .Angular2应用程序内部的路由器导航工作正常.
编辑
我正在使用此配置将已编译的Angular2资源从target/ui添加到static/ui文件夹(我的项目使用maven构建):
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>*.properties</include>
<include>templates/*.*</include>
</includes>
</resource>
<resource>
<directory>target/ui</directory>
<targetPath>static/ui</targetPath>
</resource>
Run Code Online (Sandbox Code Playgroud)
要明确的是,唯一的问题是,当我在浏览器中输入像/ ui/home/settings这样的URL时,Spring会拦截请求并抛出错误.我可以愉快地导航到/ ui,然后导航到Angular上下文中的/ home/settings.
Angular projet构建依赖于Angular CLI工具.
Spring启动项目构建依赖于Spring Boot Maven插件.
那么如何配置和构建一个在前端托管Angular应用程序的Spring Boot应用程序呢?
我的要求如下:
使用Maven作为Java构建工具
在Spring Boot引导的嵌入式Tomcat实例中运行应用程序.
高效的开发环境中的构建生命周期
可靠的后期开发环境构建
我有一个大问题。我正在尝试在 heroku 上部署 Spring Boot + Angular 2 Web 应用程序,但不知道该怎么做。我尝试了几件事,包括:
但这些都没有奏效。第一次尝试不起作用,因为我一直找不到 404,而第二次尝试不起作用,因为我认为在 Procfile.xml 中描述的位置找不到某些 jar 文件。谁能给我一个链接,一个例子,或者写一个如何实现这一点的分步说明。谢谢你。
spring-boot ×6
angular ×5
java ×4
spring ×4
angularjs ×2
heroku ×1
html5 ×1
maven ×1
routing ×1
spring-mvc ×1