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:
Oliver Drotbohm
2024-05-21 23:54:04 +02:00
parent f8283fa644
commit 4c4ac0c45e
6 changed files with 23 additions and 36 deletions

View File

@@ -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.
*

View File

@@ -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;

View File

@@ -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