我正在尝试在Spring-boot应用程序中使用yeoman角度生成器。我有以下项目结构
/project
-/src/main
-- /java
-- / resources
--- /application.properties
--- /public
---- /app
----- /index.html
----- /bower-components
----- /scripts
----- /views/**.html
----- /images
----- /styles我的目标是当应用程序加载时,从/project/src/main/resources/public/app/index.html加载index.html页面,URL应该是"localhost:8080/#/“。目前,URL类似于localhost:8080/app/index.html。
我尝试将映射放在application.properties中为:
server.context-path=/public/app我还尝试通过扩展WebMvcConfigurerAdapter来覆盖应用程序配置。这个类是:
@Configuration
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/public/" };
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController( "/" ).setViewName( "app/index" );
}
}但看起来这也不管用。有没有人可以评论一下我遗漏了什么,以及如何实现URL为"locahost:8080/#/“,即使index.html位于/src/main/resources/public/app。
注意:如果我将我的index.html页面放在/src/main/resources/public,那么URL将显示为desired locahost:8080/#/。任何帮助都是非常感谢的。
谢谢
发布于 2015-06-23 23:07:50
就我个人而言,我不确定通过localhost:8080/#/访问应用程序的索引页是否正确。因为“#”用于在当前页面上导航。请看一下关于超链接的enter link description here答案。
编辑:
看起来你在CLASSPATH_RESOURCE_LOCATIONS的问题。您是否尝试过将"classpath:/resources/"更改为"classpath:/resources/app/"
否则,您可以将您的html文件从资源文件夹移动到WEB-INF,并将InternalResourceViewResolver的配置添加到您的@ApplicationConfiguration类中,如下所示:
@Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/app/");
resolver.setSuffix(".html");
return resolver;
}我希望这能帮到你。
发布于 2015-06-24 03:54:35
在我的应用程序配置中,我添加了app文件夹
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/public/app/" };
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);然后将方法addViewControllers添加为:
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html") ;
}不需要更改我的文件夹结构(如问题所述)。
希望这对其他人也有帮助。
https://stackoverflow.com/questions/31004027
复制相似问题