java - How to get current SpringApplication instance in spring-boot programmatically? -


how current springapplication instance in spring-boot programmatically? spring docs says : springapplication has method called iswebenvironment() . don't know how tell if application web or non-web application programmtically , can applicationcontext.getenvironment() ? way , don't want solve searching xxservlet httpservletrequest ... etc.

what applicationcontext instanceof webapplicationcontext?

if you're trying determine whether or not application running in web context, can use fact when spring application started in web context, applicationcontext object have access instance of webapplicationcontext interface. therefore can write

iswebenvironment = (applicationcontext instanceof webapplicationcontext); 

there no real reason springapplication object class, sole purpose build applicationcontext.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -