今天需要引用一个Scala程序的jar包,该Scala程序通过沪深行情计算出信号点信息。我需要将信号点存入本地DB。
写好调用Scala的Service后,在单元测试Test中跑没问题,但是一旦启动Tomcat 在SpringMVC的 Task配置的定时任务中调用 或者在@Controller中调用,就会报错:
03-Jul-2017 09:43:37.831 严重 [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
org.aiotrade.lib.util.config.ConfigurationException: configDir is defined as [../conf]
but the 'development.conf' config file can not be found at [../conf/development.conf],
我打开jar包 发现在其根目录下确实有个development.conf 配置文件。于是拷贝出来,打包到我自己的web工程下。但是我尝试了将该配置文件打包到web程序的任何一级目录,依然报错找不到该配置文件。
单步调试进去,看到源码中对于Scala的配置源码:
private Option configDir$lzycompute() {
synchronized(this) {
if(!this.bitmap$0) {
this.configDir = .MODULE$.apply(scala.Predef..MODULE$.wrapRefArray((Object[])(new String[]{"../conf", "../etc"}))).find(new Serializable() {
public static final long serialVersionUID = 0L;
public final boolean apply(String x) {
File f = new File(x);
return f.exists() && f.isDirectory();
}
});
this.bitmap$0 = true;
}
BoxedUnit var10000 = BoxedUnit.UNIT;
}
return this.configDir;
}
该段代码配置了 当在容器中运行时 会去lib库的上上级的conf目录下去找。因此在Tomcat容器中运行时,把development.conf 配置文件放到Tomcat的conf路径下,问题解决。