首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring-boot配置

Spring-boot配置
EN

Stack Overflow用户
提问于 2015-06-23 21:24:06
回答 2查看 1.5K关注 0票数 1

我正在尝试在Spring-boot应用程序中使用yeoman角度生成器。我有以下项目结构

代码语言:javascript
复制
/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中为:

代码语言:javascript
复制
server.context-path=/public/app

我还尝试通过扩展WebMvcConfigurerAdapter来覆盖应用程序配置。这个类是:

代码语言:javascript
复制
@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/#/。任何帮助都是非常感谢的。

谢谢

EN

回答 2

Stack Overflow用户

发布于 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类中,如下所示:

代码语言:javascript
复制
@Bean 
public InternalResourceViewResolver getInternalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/app/");
        resolver.setSuffix(".html");
        return resolver;
}

我希望这能帮到你。

票数 0
EN

Stack Overflow用户

发布于 2015-06-24 03:54:35

在我的应用程序配置中,我添加了app文件夹

代码语言:javascript
复制
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添加为:

代码语言:javascript
复制
@Override
    public void addViewControllers(ViewControllerRegistry registry) { 
        registry.addViewController("/").setViewName("forward:/index.html") ;
    }

不需要更改我的文件夹结构(如问题所述)。

希望这对其他人也有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31004027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档