2

I'm using Spring Boot on weblogic 10.3.6; however we usually use the embedded tomcat during development.

I'd like to enable a specific Spring profile when on weblogic to accomodate for different configuration/beans to be used when on wl. Since I'm forced to use a web.xml on that ancient version of the application server, I'd like to use web.xml to activate the weblogic profile I need.

This is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>my.class.annotated.with.SpringBootApplication</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextAttribute</param-name>
            <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

So far I've seen suggestion to use

<context-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>weblogic</param-value>
</context-param>

or

<init-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>weblogic</param-value>
</init-param>

in the DispatcherServlet configuration.

I even tried configuring an ApplicationContextInitializer, but SpringBootContextLoaderListener provides his own initializer.

Is there a proper way to accomplish what I want? I can't put weblogic configuration in main application.yml because that would break the embedded tomcat configuration we are using for development.

p91paul
  • 1,104
  • 10
  • 26
  • Haven't seen it done in web.xml. You can add an environment variable to your servers startup command `-Dspring.profiles.active=weblogic` or by some oither means https://stackoverflow.com/questions/23620163/best-way-to-set-environmental-variables-in-weblogic-startup – Alan Hay Mar 01 '19 at 08:13
  • I'd very much like to avoid that since the weblogic domain is shared with other applications, and I have to interact with unpleasant people to be able to get that to happen. I consider it to be my last chance. – p91paul Mar 01 '19 at 08:18
  • 1
    web.xml should work. https://www.baeldung.com/spring-profiles Other approches - do programatically mabe you can read some env var (OS?) that indicates running on weblogic. Or, set web logic as the default profile and then nothing needs to be done on the server, only locally? – Alan Hay Mar 01 '19 at 08:30

0 Answers0