GH-614 - Expose factory method to create a (SpringBoot)ApplicationRuntime.
We now expose ApplicationRuntime.of(ApplicationContext) to create a SpringBootApplicationRuntime as that's needed a lot in integration tests for runtime and observability components.
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.modulith.runtime;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstraction of the application runtime environment. Primarily to keep references to Spring Boot out of the core
|
||||
* observability implementation.
|
||||
@@ -23,6 +26,19 @@ package org.springframework.modulith.runtime;
|
||||
*/
|
||||
public interface ApplicationRuntime {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ApplicationRuntime} for the given {@link ApplicationContext}.
|
||||
*
|
||||
* @param context must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
public static ApplicationRuntime of(ApplicationContext context) {
|
||||
|
||||
Assert.notNull(context, "ApplicationContext must not be null!");
|
||||
|
||||
return new SpringBootApplicationRuntime(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the application.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.modulith.runtime.autoconfigure;
|
||||
package org.springframework.modulith.runtime;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.modulith.runtime.ApplicationRuntime;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -57,8 +57,8 @@ class SpringModulithRuntimeAutoConfiguration {
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnMissingBean(ApplicationRuntime.class)
|
||||
static SpringBootApplicationRuntime modulithsApplicationRuntime(ApplicationContext context) {
|
||||
return new SpringBootApplicationRuntime(context);
|
||||
static ApplicationRuntime modulithsApplicationRuntime(ApplicationContext context) {
|
||||
return ApplicationRuntime.of(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user