我的项目使用 catalina.base 系统属性来获取相对于该属性的文件夹位置的资源。在 Eclipse 中工作时,我通过 -Dcatalina.base=。作为应用程序 Main 类的 VM 参数。
我的 Main 类是这样实现的:
@ComponentScan
@EnableAutoConfiguration
public class Main {
private static final Logger logger = LogManager.getLogger();
public static void main(String[] args) {
if ( logger.isDebugEnabled() ) {
String debugCatalinaBase = System.getProperty("catalina.base");
// here catalinaBase is set to "." as expected.
logger.debug("catalinaBase: {}", debugCatalinaBase);
}
SpringApplication.run(Main.class, args);
}
}
作为这个项目的一部分,我有一个 ApplicationConfig 类,它是这样实现的:
@Configuration
public class ApplicationConfig {
private static final Logger logger = LogManager.getLogger();
@Value("${catalina.base}")
private String catalinaBase;
@Bean
public Properties jndiProperties() {
if ( logger.isDebugEnabled() ) {
String debugCatalinaBase = System.getProperty("catalina.base");
// here catalinaBase is set to "C:\Users\theUser\AppData\Local\Temp\tomcat.8558104871268204693.8081". NOT as expected!!!
logger.debug("catalinaBase: {}", debugCatalinaBase);
}
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
CnsContextFactory.class.getName());
properties.setProperty(Context.PROVIDER_URL,
"file:" + catalinaBase + "\\conf\\jndi.properties");
return properties;
}
@Bean( name = "propertyConfigurer" )
public static PropertySourcesPlaceholderConfigurer propertyConfigurer() {
PropertySourcesPlaceholderConfigurer configurer =
new PropertySourcesPlaceholderConfigurer();
return configurer;
}
}
正如您在代码片段的注释中看到的那样,在 ApplicationConfig 中 catalina.base 系统属性已更改,我不确定为什么或在哪里发生这种情况?
有关信息,我的项目使用 spring-boot-starter-xxx:1.1.4.RELEASE jar 和 spring-xxx:4.0.6.RELEASE jar。
另外,我还有另一个项目,它遵循几乎相同的整体模式并使用相同的 jars,并且该项目总是看到 catalina.base 设置为“。” 正如预期的那样。所以我想知道问题是否与在有问题的项目中加载弹簧配置的顺序有关,还是与这些方面有关?
提前感谢您对此的任何帮助。下午