Application uses Spring Boot 2.0.2.RELEASE

application.properties file has the following entry: spring.profiles.active=local

When running the application (in IntelliJ or by running the application jar from the command line), the application will sometimes ignore the active profile setting (around 30% of the time). The application configurations that are annotated to be registered for a 'local' profile are ignored, and the console output will display this line: No active profile set, falling back to default profiles: default

This behavior is unpredictable. The only solution is to try restarting the application (sometimes multiple times) until the active profile is set correctly.

The salient point is that restarting the application without making any changes will eventually correct the problem.

Let me know what other information you need. I can't hand over this application, and creating an app that reproduces this problem is probably not viable (none of my other Spring Boot apps behave this way, and nothing obvious makes this one different). Perhaps a logging trace will provide helpful information?

Comment From: philwebb

It's interesting that only one of your applications shows this behavior. Are you able to add logging.level.org.springframework=TRACE to your application.properties and get some log output of the failure?

Comment From: 730alchemy

Enabling trace on org.springframework results in a few hundred pages of log data. Do you have a more refined trace? Otherwise I can upload the whole log.

When I search for 'profile' I get the following contiguous lines:

o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.profiles.active' in PropertySource 'servletConfigInitParams'
o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.profiles.active' in PropertySource 'servletContextInitParams'
o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.profiles.active' in PropertySource 'systemProperties'
o.s.c.e.PropertySourcesPropertyResolver  : Searching for key 'spring.profiles.active' in PropertySource 'systemEnvironment'
o.s.c.e.PropertySourcesPropertyResolver  : Could not find key 'spring.profiles.active' in any property source

Comment From: 730alchemy

Another clue. I added logging.level.org.springframework=TRACE to applications.properties. When I start the application, if the console output states No active profile set, falling back to default profiles: default, then no tracing statements are logged. If the console output states that the active profile is 'local', then the console output includes tracing statements.

Remember, I added logging.level.org.springframework=TRACE to application.properties, not to application-local.properties. It seems like the Spring Framework is sometimes failing to either find, open, or read the application.properties file.

Comment From: philwebb

Is there anything else that's unusual about this specific application? You said that you have others that don't fail in the same way.

If you're able to debug a failing application you could try adding breakpoints in ConfigFileApplicationListener. There's a load method in that class that includes a lot of log output describing why a specific Resource is skipped. My guess is resource.exists() returns false but I don't know why that would be.

Comment From: 730alchemy

I added breakpoints to the load(PropertySourceLoader, String, Profile, DocumentFilter, DocumentConsumer) method in ConfigFileApplicationListener. When the application is able to find the active profile, resource.exist() returns true on the invocation when the location parameter equals classpath:/application.properties. When the application starts without finding the active profile, resource.exists() returns false on every invocation of load, including when the location parameter equals classpath:/application.properties

Comment From: philwebb

@730alchemy Is it possible that IntelliJ hasn't copies the application.properties to the classpath for some reason? Are you doing anything special with that file in your build?

The ClassPathResource.exists() method just delegates to standard JVM calls so it's hard to see why it would go wrong.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: 730alchemy

Although this problem was ongoing for a month, the problem has not recurred in the past 10 days. I've looked at code changes around the time of the last occurrence, but nothing jumps out as a possible cause. I checked out a commit from 3 weeks ago and went through 10 cycles of clean/compiler/run, but every time the active profile was correctly detected. Two weeks ago we upgraded from Spring Boot 2.0.0 to 2.0.2, but I don't think that would explain a 3-week old commit that's still on 2.0.0 no longer exhibiting this problem.

On our end, we no longer have an issue. Sorry we can't be of more help locating the cause of our original problem.

Comment From: snicoll

Thanks for the feedback, I am afraid there's not much we can do it without a sample that shows there is a problem in Spring Boot. We can reopen if that changes.

Comment From: HattoriHenzo

I have the same issue, using Spring Batch with Spring Boot (2.0.0) and my Batch do not execute. Here is my stack trace :

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)

"2018-08-14 16:27:32 - Starting Application on MA18-012.local with PID 19662 xxx
""2018-08-14 16:27:32 - No active profile set, falling back to default profiles: default
""2018-08-14 16:27:34 - HikariPool-1 - Starting...
""2018-08-14 16:27:35 - HikariPool-1 - Start completed.
""2018-08-14 16:27:35 - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
""2018-08-14 16:27:35 - HHH000412: Hibernate Core {5.2.14.Final}
""2018-08-14 16:27:35 - HHH000206: hibernate.properties not found
""2018-08-14 16:27:35 - HHH80000001: hibernate-spatial integration enabled : true
""2018-08-14 16:27:35 - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
""2018-08-14 16:27:35 - HHH000400: Using dialect: org.hibernate.spatial.dialect.mysql.MySQL5SpatialDialect
""2018-08-14 16:27:35 - HHH000400: Using dialect: org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect
""2018-08-14 16:27:38 - HikariPool-1 - Shutdown initiated...
""2018-08-14 16:27:38 - HikariPool-1 - Shutdown completed.
" 

Comment From: wilkinsona

@HattoriHenzo As @snicoll said above, that's not much that we can do without a sample that reproduces the problem. Perhaps you could do some further analysis similar to that done by @730alchemy above.

Comment From: HattoriHenzo

@wilkinsona the issue occurs when I changed my code to integrate chunk in my batch. Any of the steps define in my job does not execute. Am I missing an annotation or something else?

@Configuration
@EnableBatchProcessing
public class BatchConfiguration extends DefaultBatchConfigurer {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public LoadTasklet loadTasklet() {
        return new LoadTasklet();
    }

    @Bean
    public ArchiveTasklet archiveTasklet() {
        return new ArchiveTasklet();
    }

    @Bean
    public UnzipTasklet unzipTasklet() {
        return new UnzipTasklet();
    }

    @Bean
    public RemoveTasklet removeTasklet() {
        return new RemoveTasklet();
    }

    @Bean
    protected Step loadFile() {
        return stepBuilderFactory.get("loadFile")
                .tasklet(loadTasklet())
                .build();
    }

    @Bean
    protected Step archiveFile() {
        return stepBuilderFactory.get("archiveFile")
                .tasklet(archiveTasklet())
                .build();
    }

    @Bean
    protected Step unzipFile() {
        return stepBuilderFactory.get("unzipFile")
                .tasklet(unzipTasklet())
                .build();
    }

    @Bean
    protected Step removeFile() {
        return stepBuilderFactory.get("removeFile")
                .tasklet(removeTasklet())
                .build();
    }

    @Bean
    public FlatFileItemReader<Record> recordReader() {
        return new RecordReader().getRecordReader();
    }

    @Bean
    public RecordProcessor recordProcessor() {
        return new RecordProcessor();
    }

    @Bean
    public RecordWriter recordWriter() {
        return new RecordWriter();
    }

    @Bean
    public Step processFile() {
        return stepBuilderFactory.get("processFile")
                .<Record, Shop>chunk(1000)
                .reader(recordReader())
                .processor(recordProcessor())
                .writer(recordWriter())
                .build();
    }

    @Bean
    public Job jobExecution() {
        return jobBuilderFactory.get("BatchJob")
                .flow(loadFile())
                .next(archiveFile())
                .next(unzipFile())
                .next(removeFile())
                .next(processFile())
                .end()
                .build();
    }

    @Override
    public void setDataSource(DataSource datasource) {
        // Spring Batch to ignore any data source
    }
}

Before my modifications, the batch was working with the stacktrace bellow :

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)

"2018-08-08 15:36:03 - Starting Application on MA18-012.local with PID 39543 
""2018-08-08 15:36:05 - HikariPool-1 - Starting...
""2018-08-08 15:36:05 - HikariPool-1 - Start completed.
""2018-08-08 15:36:06 - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
""2018-08-08 15:36:06 - HHH000412: Hibernate Core {5.2.14.Final}
""2018-08-08 15:36:06 - HHH000206: hibernate.properties not found
""2018-08-08 15:36:06 - HHH80000001: hibernate-spatial integration enabled : true
""2018-08-08 15:36:06 - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
""2018-08-08 15:36:06 - HHH000400: Using dialect: org.hibernate.spatial.dialect.mysql.MySQL5SpatialDialect
""2018-08-08 15:36:06 - HHH000400: Using dialect: org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect
""2018-08-08 15:36:09 - Started Application in 6.294 seconds (JVM running for 6.812)
""2018-08-08 15:36:09 - Loading the file name
""2018-08-08 15:36:23 - Downloading the file
""2018-08-08 15:36:24 - Archiving the file 
""2018-08-08 15:36:24 - Unzipping the file
""2018-08-08 15:36:24 - Removing the file
""2018-08-08 15:36:51 - Reading the file
""2018-08-08 15:36:52 - HHH000397: Using ASTQueryTranslatorFactory
""2018-08-08 15:36:54 - HikariPool-1 - Shutdown initiated...
""2018-08-08 15:36:54 - HikariPool-1 - Shutdown completed.

I can give more details if needed.

Comment From: wilkinsona

I can give more details if needed.

Yes, please. I can't see anything there that shows the link with active profiles being periodically ignored. If you believe you've found a bug, please open a new issue with a complete, minimal example (something that with can unzip or git clone and run) that reproduces the problem. If you're looking for some guidance, please ask a question on Stack Overflow or come and chat with the community on Gitter.

Comment From: HattoriHenzo

@wilkinsona You are wright, I am not sure it is something related to the profile but this is the only significant message I have in my stacktrace. I will ask on Stack Overflow or on Gitter. This issue is very strange. Thank you.

Comment From: Dhivyadinesh

2019-09-12 16:51:06.783 INFO 16714 --- [ main] demo.DemoApplication : Starting DemoApplication on guest-pc with PID 16714 (/home/guest/Documents/workspace-spring-tool-suite-4-4.3.2.RELEASE/demo/target/classes started by guest in /home/guest/Documents/workspace-spring-tool-suite-4-4.3.2.RELEASE/demo) 2019-09-12 16:51:06.788 INFO 16714 --- [ main] demo.DemoApplication : No active profile set, falling back to default profiles: default 2019-09-12 16:51:07.365 INFO 16714 --- [ main] demo.DemoApplication : Started DemoApplication in 0.871 seconds (JVM running for 1.277) i am getting like this...there is an any solution for this?

Comment From: wilkinsona

@Dhivyadinesh Thus far we've been unable to reproduce the problem so, unfortunately, there's no known solution. I have you have example that reproduces the problem then please share it with us. Alternatively, you could perform some analysis similar to that done above by @730alchemy.

Comment From: Dhivyadinesh

@Dhivyadinesh Thus far we've been unable to reproduce the problem so, unfortunately, there's no known solution. I have you have example that reproduces the problem then please share it with us. Alternatively, you could perform some analysis similar to that done above by @730alchemy. @730alchemy thank you.....

Comment From: jonno85

Hi All, I have the same problem with Spring boot 2.2.5. Following the suggestion above I have enabled the properties in my yaml file:

 logging:
     level:
         org.springframework: TRACE

that solved the issue in loading the application-local.yml content. What it is weird, removing afterward that configuration, the application starts to recognise the 'local' profile again. Totally strange.

Comment From: MatheusDomenicale

Resolvi este problema assim - procure alguma Exclued que esteja com (**), caso encontre, clique no botão remover e mudara para (None) e depois compile o projeto novamente. Spring

Comment From: opticSquid

Resolvi este problema assim - procure alguma Exclued que esteja com (**), caso encontre, clique no botão remover e mudara para (None) e depois compile o projeto novamente. Spring

Can you use English please. Could not understand

Comment From: chrismmilburn

I have this problem as well, Spring boot v2.7.4 It occurs when I try to run a jar file :-

java -Dspring.profiles.active=dev -jar trade-feed.jar

I get the 'No active profile set, falling back to 1 default profile: "default" ' error Like your previous reporter, putting 'logging.level.org.springframework=TRACE' in application.properties does not result in any trace output. The only other clues i can give are :- 1. It works on a linux box but not on a windows box (same command and jar file) 2. It works on my colleagues windows box (same command and jar file) 3. It works if I run from within intellij (not using the jar file).

Comment From: philwebb

@chrismmilburn Spring Boot 2.7 is no longer under OSS support, please upgrade to a supported version. It sounds like something specific to your environment if it works on other machines. Perhaps checking the contents of System.getProperties() might be a good place to start to check if spring.profiles.active is set correctly.