Weblogic 12c: How to pass an “active profile” to a Spring boot application?

I am developing a Spring boot application and I have to run it on our server Weblogic 12cas a war.

I am trying to find a way to pass Spring's default active profile (info here and here ) without requiring setting the environment variable on the computer itself. I would like to specify this profile using the Weblogic admin console, if possible.

I tried playing with the parameters " Environment / Servers / MyServer / Server Start / Arguments", but I could not make Spring load the specified profile in this way. I tried, unsuccessfully:

spring.profiles.active=dev
-Dspring.profiles.active='dev'
-Dspring.profiles.active=dev
-spring.profiles.active=dev
--spring.profiles.active=dev

Any idea if you can submit spring.profiles.activeto Spring using Weblogic? I need to pass " dev", " acc" or " prod".

UPDATE: I would accept an answer explaining any easy way to have different files .propertiesused for application configurations, depending on the environment in which the Sprint download application runs. These files .propertiescan be linked in the application itself or can be external. But I need to touch the system. Weblogic works at least as much as possible ... There are no environment variables and, ideally, no changes to Weblogic files! Ideally, the solution will include some manipulations performed using the Weblogic admin console, for example, a method for passing a parameter representing the current environment to the Spring boot application, so the correct file is used application.[ENVIRONMENT].properties.

2. application.properties, . , , . , ... , , Weblogic! Environment / Servers / MyServer / Server Start / Arguments, ?

3: . , "Environment / Servers / MyServer / Server Start / Arguments" , NodeManager? , spring.profiles.active=dev!

+4
4

application.propeties, :

# PROFILES
spring.profiles.active= # Comma-separated list of active profiles.

, WAR ( , , ), @PropertySource(value = "classpath:application.dev.properties") , .

+2

, :

  • "DEPLOYMENT_ENV" WebLogic -D, DEPLOYMENT_ENV (dev, test, acc, prod,...)
  • Spring , "classpath: configuration/${DEPLOYMENT_ENV}/some_property_filename.properties"
  • JUnit @TestPropertySource
  • Spring , : ( -), ( JUnit @ActiveProfiles) ... beans.

, Spring , , catch22.

Spring, bean , , beans.

+1

, , , . . " UPDATE 2" ...

- . , application.properties.

+1

Spring Spring , , , Spring , .

, Spring , .. , .

Spring Boot PropertySource, .

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config, , , , JNDI , .

Spring (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config) JEE, JNDI

  • , , , .., , .
    • : Weblogic.
  • ServletConfig ServletContext , .

. , , .

, , Spring JEE :

  • JNDI
  • application.properties

, packaged application- {profile}.properties, , .

, JEE *, JNDI.

[*] " JEE" , Spring Cloud Config (https://cloud.spring.io/spring-cloud-config/).

, Weblogic JNDI , Spring Boot Spring JNDI.

:

  • Weblogic, (dev, pre, pro,...)
  • JNDI Spring Environment: ${jndi.var} application.properties, @Value ($ {jndi.var}) ..
    • Note that Spring Boot populates the Spring environment with JNDI attributes, so you can use them the same way you use the properties inside the application.properties file.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1659856/


All Articles