Skip to content

Commit

Permalink
Register ApplicationContext bean with class (#584)
Browse files Browse the repository at this point in the history
* Register ApplicationContext bean with class

* Assert none of the beans' types are null

* Fix typo

* Refactor to use Micronaut application context

* Use correct method to retrieve all bean defs
  • Loading branch information
Phoenix-Starlight authored May 30, 2024
1 parent dd80665 commit 8323476
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void registerBeanDefinitions(
ppd.setBeanClass(MicronautPostProcess.class);
ppd.setInstanceSupplier(() -> new MicronautPostProcess(context));
registry.registerBeanDefinition("micronautPostProcess", ppd);
genericBeanDefinition.setBeanClass(context.getClass());
genericBeanDefinition.setInstanceSupplier(() -> context);
genericBeanDefinition.setDestroyMethodName("stop");
registry.registerBeanDefinition(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.micronaut.spring.boot.starter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import io.micronaut.context.ApplicationContext;
import io.micronaut.context.annotation.Bean;
Expand All @@ -15,6 +17,7 @@
import org.springframework.core.env.Environment;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -51,6 +54,12 @@ void testEnableMicronaut() {
assertEquals("default", fooBean.getConfiguration().getName());
assertEquals(3, fooBeanList.size());
assertTrue(context.isRunning());
assertFalse(
context.getAllBeanDefinitions()
.stream()
.map(bean -> bean.getBeanType())
.anyMatch(Objects::isNull)
);
}
}

Expand Down

0 comments on commit 8323476

Please sign in to comment.