angularjs 访问index.html,angularjs-春季启动应用程序找不到index.html

我是第一次手工将AngularJS和spring-boot应用程序连接在一起.我遇到的问题是我的@RestController没有返回索引页:

@RestController

public class IndexController {

@RequestMapping("/")

public String index(){

System.out.println("Looking in the index controller.........");

return "index";

}

}

目录:

sR7VG.png

它继续呈现默认的404错误页面:

1s49m.png

—————-更新1 ——————

我添加了一个配置文件:

@Configuration

public class IndexPageConfiguration {

@Bean

public InternalResourceViewResolver viewResolver(){

InternalResourceViewResolver resolver = new InternalResourceViewResolver();

resolver.setPrefix("/app/");

resolver.setSuffix(".html");

return resolver;

}

}

RestController

@RestController

public class IndexController {

@RequestMapping("/")

public String index(){

System.out.println("Looking in the index controller.........");

return "index";

}

}

主类:

@SpringBootApplication(scanBasePackages = { "com.serviceImpl","com.service","com.config" },exclude = { ErrorMvcAutoConfiguration.class })

public class SpringCrudApplication {

public static void main(String[] args) {

SpringApplication.run(SpringCrudApplication.class, args);

}

}

上面的主类仍返回默认的404错误页面.

解决方法:

您需要配置InternalRosourceViewResolver以让spring知道您的jsp位置

@Bean

public InternalResourceViewResolver viewResolver() {

InternalResourceViewResolver resolver = new InternalResourceViewResolver();

resolver.setPrefix("/app/");

resolver.setSuffix(".html");

return resolver;

}

因此,Spring会将位置和后缀追加并追加到返回的View中.

我认为将视图分开保存在任何其他文件夹中并根据其配置文件夹位置是一个好主意.

如果您想继续当前的设置

您应该从控制器返回“ /app/index.html”.

Spring Boot提供了白标错误页面,以在发生服务器端错误/异常时隐藏您的堆栈跟踪,这将有助于我们保护代码免遭入侵者的侵害.

如果要摆脱白标错误.

在您的@SpringBootApplication中指定排除ErrorMvcAutoConfiguration.class

@SpringBootApplication(scanBasePackages = { "com.ekart.app" }, exclude = { ErrorMvcAutoConfiguration.class })

如果不使用@SpringBootApplication注释,则应在@EnableAutoConfiguration注释中提供相同的排除项

标签:angularjs,spring

来源: https://codeday.me/bug/20191118/2032096.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值