spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Spring Profile Active is not setting

Open mrvaruntandon opened this issue 11 months ago • 0 comments

I am trying to run the below command to start a springboot application

java -Dlog4j.configuration=file:///log4j.properties -Dspring.profiles.active=local -cp ./target/app-1.0.0-SNAPSHOT-jar-with-dependencies.jar MainClass

the jar above is prepared using maven-assembly-plugin the configuration for which is

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>${maven-assembly-plugin.version}</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>MainClass</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Main class looks like

@SpringBootApplication
@Slf4j
public class MainClass {
    public static void main(String... args) {
        log.info(System.getProperty("spring.profiles.active"));
        ApplicationContext ctx = SpringApplication.run(AcctrvDataProcessor.class, args);
        log.info(Arrays.toString(ctx.getEnvironment().getActiveProfiles()));
        int exitCode = SpringApplication.exit(ctx);
        System.exit(exitCode);
    }
}

When I run the application from the above command I am seeing the below log:

15:45:07.091 [main] INFO MainClass - local
15:46:07.091 [main] INFO MainClass - No active profile set, falling back to 1 default profile: "default"

What could be preventing the spring profile actives from being set?

mrvaruntandon avatar Mar 13 '24 13:03 mrvaruntandon