当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Get Application Name while loading Spring @Configuration file

问题描述:

I am using Spring Framework 4. I have common project like TestApplication which is Aspect based and pull logs on applications App1 and App2.

I am using @Configuration completely annotation based configuration in TestApplication.

App1 and App2 have separate spring Configuration and hence separate contexts and loads TestApplication individually.

Question:

while App1 is loaded, TestApplication's @Configuration gets loaded and within that file i need to get application name as App1.

Similarly when App2 is loaded, within @Configuration file of TestApplication I need to get application name as App2.

I tried using ApplicationContext's getApplicationName() method and works well locally. But in DEV/PROD regions might be using DNS and hence not applicable.

Suggestions please.

edited:

One approach identified is to update web.xml of application with context-param and value and access it via @Value(value="${context-param-name}") annotation. Works fine but requires property place holder to be configured in spring xml.

分享给朋友:
您可能感兴趣的文章:
随机阅读: