简体   繁体   English

由于指定的概要文件而跳过了XML bean定义文件[默认]不匹配

[英]Skipped XML bean definition file due to specified profiles [default] not matching

We have a Spring application deployed on tomcat, and it does not start. 我们在tomcat上部署了一个Spring应用程序,并且该应用程序无法启动。

The application error is as follows: 应用程序错误如下:

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested 
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [${hibernate.connection.driver_class}]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1564)
... 49 more

We do have a properties file defined at: /opt/tomcat/appname/tomcat8-2 with three files: config.properties, core-ws.proprties, and log4j-config.xml 我们确实在/ opt / tomcat / appname / tomcat8-2中定义了一个属性文件,其中包含三个文件:config.properties,core-ws.proprties和log4j-config.xml。

We know ${TOMCAT_CONFIG_HOME} is defined to be: /opt/tomcat/appname/tomcat8-2 我们知道$ {TOMCAT_CONFIG_HOME}定义为:/ opt / tomcat / appname / tomcat8-2

We know that the file permissions are correct, the user running tomcat has read permissions to the directories and files in this config directory. 我们知道文件权限是正确的,运行tomcat的用户具有对该配置目录中的目录和文件的读取权限。 I can as that tomcat user edit/read the properties file. 我可以像那个tomcat用户一样编辑/读取属性文件。 So, we know it's not a permissions issue. 因此,我们知道这不是权限问题。

From the app log, we have this error message: 从应用程序日志中,我们收到以下错误消息:

Skipped XML bean definition file due to specified profiles [default] not matching: class path resource [spring/app-platform-entity-context.xml]

The Spring application context file has this for properties: Spring应用程序上下文文件具有以下属性:

<beans profile="default">
     <context:property-placeholder location="file:${TOMCAT_CONFIG_HOME}/core-ws.properties" />
 </beans>

Finally here is what the core-ws.properties looks like: 最后,这是core-ws.properties的样子:

hibernate.connection.url=jdbc:oracle:thin:@//123.456.789/APP_DB
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.username=some_db_user
hibernate.connection.password=some_db_password

So, I have looked into this for a coupe of days, and I am at my wits end. 因此,我已经花了几天的时间研究这个问题,并且我精打细算。 I can tell you we have no problem with the log4j-config.xml file. 我可以告诉您,log4j-config.xml文件没有问题。 The app can find it, and read it just fine. 该应用程序可以找到它,并很好地阅读它。 it is just this one parameter that seems to be crashing the app ... 仅仅是这个参数似乎使应用程序崩溃了...

Any help with this matter would be much appreciated. 对此问题的任何帮助将不胜感激。 Thanks! 谢谢!

The reason that XML file was skipped was because we had a -Dspring.profiles.active=prod in our CATALINA_OPTS setup. 跳过XML文件的原因是因为我们的CATALINA_OPTS设置中包含-Dspring.profiles.active = prod。

We didn't find it until we started exporting what the values were as tomcat started. 直到我们开始导出tomcat启动时的值后,我们才找到它。

Once we removed this line, our [default] profile tookover as it should. 删除此行后,我们的[默认]配置文件将按原样接管。

Thanks! 谢谢!

Answering this for stand-alone apps: 为独立应用程序回答以下问题:

In my case it was because of the order of setting up ApplicationContext, I was loading the xml file, before setting the profile. 就我而言,这是由于设置ApplicationContext的顺序,我在设置配置文件之前正在加载xml文件。 The correct order is: 正确的顺序是:

  GenericXmlApplicationContext ctx =
            new GenericXmlApplicationContext();
    ctx.getEnvironment().setActiveProfiles("dev");
    ctx.load("com/profiles/*-config.xml");
    ctx.refresh();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM