Package io.jmix.core
Class ApplicationInfoProvider
java.lang.Object
io.jmix.core.ApplicationInfoProvider
@Component("core_ApplicationInfoProvider")
@ConditionalOnClass(org.springframework.boot.web.server.context.WebServerApplicationContext.class)
public class ApplicationInfoProvider
extends Object
Provides information about the running application (host, port, active profiles, etc.) and stores it
to the
app-info.json file in the conf directory for development tools.
The file is created on application startup and removed on shutdown. It is not created if the JVM is bootstrapped by a test framework, because tests may run from the same directory as a normally running application instance and must not affect its file. On shutdown, the file is removed only if it still belongs to this application instance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected Stringprotected CorePropertiesprotected org.springframework.core.env.Environmentprotected Stringprotected Stringprotected static final Stringprotected Stringprotected intprotected Stringprotected OffsetDateTimeStack trace prefixes of test framework launchers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.gson.JsonArrayprotected voidprotected com.google.gson.JsonObjectgetHost()intgetPort()protected voidinitValues(org.springframework.context.ConfigurableApplicationContext context) protected booleanDetects that the JVM was bootstrapped by a test framework by inspecting the current thread's stack trace.protected booleanisOwnAppInfoFile(Path fileLocation) Checks that the file was created by this application instance.voidonApplicationReady(org.springframework.boot.context.event.ApplicationReadyEvent event) protected voidprotected voidprotected Pathprotected Stringprotected StringresolveFullUrl(String protocol, String host, int port, String contextPath) protected Stringprotected intresolvePort(org.springframework.context.ConfigurableApplicationContext context) protected Stringprotected voidprotected boolean
-
Field Details
-
APP_INFO_DIR_NAME
- See Also:
-
APP_INFO_FILE_NAME
- See Also:
-
INSTANCE_ID_PROPERTY
- See Also:
-
TEST_LAUNCHER_STACK_PREFIXES
Stack trace prefixes of test framework launchers. Same approach as in Spring Boot DevTools (DevToolsEnablementDeducer): if the application is bootstrapped by a test framework, the application info file must not be created or removed, because such a JVM may share the conf directory with a normally running application instance. -
environment
@Autowired protected org.springframework.core.env.Environment environment -
coreProperties
-
instanceId
-
host
-
port
protected int port -
contextPath
-
protocol
-
fullUrl
-
activeProfiles
-
startupTime
-
-
Constructor Details
-
ApplicationInfoProvider
public ApplicationInfoProvider()
-
-
Method Details
-
onApplicationReady
@EventListener public void onApplicationReady(org.springframework.boot.context.event.ApplicationReadyEvent event) -
getHost
-
getPort
public int getPort() -
getContextPath
-
getProtocol
-
getFullUrl
-
getActiveProfiles
-
getStartupTime
-
initValues
protected void initValues(org.springframework.context.ConfigurableApplicationContext context) -
resolveProtocol
-
resolveHost
-
resolvePort
protected int resolvePort(org.springframework.context.ConfigurableApplicationContext context) -
resolveContextPath
-
resolveActiveProfiles
-
resolveFullUrl
-
createAppInfoFile
protected void createAppInfoFile() -
createJson
protected com.google.gson.JsonObject createJson() -
writeFile
-
resolveAppInfoFileLocation
-
createActiveProfilesJsonArray
protected com.google.gson.JsonArray createActiveProfilesJsonArray() -
shutdownHookOperation
protected void shutdownHookOperation() -
removeAppInfoFile
protected void removeAppInfoFile() -
isOwnAppInfoFile
Checks that the file was created by this application instance. The file may have been overwritten by another instance launched from the same directory, then it must not be removed on shutdown. -
registerShutdownHook
protected void registerShutdownHook() -
isLaunchedFromTest
protected boolean isLaunchedFromTest()Detects that the JVM was bootstrapped by a test framework by inspecting the current thread's stack trace.
-