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
Post a Comment