【springBoot】加了CommandLineRunner之后静态文件找不到了

我的大神梦 2019-08-12 03:47:10
加了CommandLineRunner之后页面打开后js和css都报404了,请教下原因

指改动了两个地方
1.在启动类上加了注解@EnableWebMvc

2.增加了如下类
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;


/**
* 配置自动启动浏览器
*/

@Component
public class MyCommandRunner implements CommandLineRunner {

@Value("${server.port}")
private String port;

@Override
public void run(String... args) {
try {
Runtime.getRuntime().exec("cmd /c start http://localhost:" + port + "/gxs");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
...全文
215 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
我的大神梦 2019-08-12
  • 打赏
  • 举报
回复
找到问题原因了,是因为加了注解@EnableWebMvc导致的,具体原因可以参见下面博客 走你

67,542

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧