我将 Spring Boot 应用程序的视图配置设置为:
@Configuration
public class ViewConfig extends WebMvcConfigurerAdapter {
public static final String[] SCRIPTS = {
"nashorn/ejs.min.js",
"nashorn/polyfill.js",
"nashorn/render.js"
};
@Bean
public ViewResolver viewResolver() {
ScriptTemplateViewResolver viewResolver = new ScriptTemplateViewResolver();
viewResolver.setPrefix("templates/");
viewResolver.setSuffix(".ejs");
return viewResolver;
}
@Bean
public ScriptTemplateConfigurer viewConfigurer() {
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
configurer.setEngineName("nashorn");
configurer.setScripts(SCRIPTS);
configurer.setRenderFunction("render");
configurer.setSharedEngine(false);
return configurer;
}
}
我的Maven结构为:
App
|-- pom.xml
`-- src
|-- main
|-- java
| `-- config
| `-- ViewConfig.java
| `-- Application.java
|-- resources
| `-- nashorn
| `-- ejs.min.js
| `-- polyfill.js
| `-- render.js
| `-- templates
| `-- index.ejs
但是,当我使用命令运行时,我遇到mvn spring-boot:run
了一个问题,无法加载具有根本原因的脚本:
java.lang.IllegalStateException: Resource [nashorn/ejs.min.js] not found
我的目的是我想用 Java 和 ReactJs 构建一个同构应用程序,但我一周前遇到了这些问题,直到现在我无法解决这些问题。