`package code;

import b.BController; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

/ * 测试启动器 * * @author: Troy.Chen(無心道, 15388152619) * @version: 2024-07-30 20:50 / @Slf4j @EnableAsync @EnableScheduling @ConfigurationPropertiesScan @SpringBootApplication( scanBasePackages = {"a"}, exclude = {DataSourceAutoConfiguration.class, MongoAutoConfiguration.class} ) public class BootStarterTest { public static void main(String[] args) throws Exception { ConfigurableApplicationContext applicationContext = SpringApplication.run(BootStarterTest.class, args); subContext(applicationContext); }

public static ApplicationContext subContext(ApplicationContext parentContext) {
    AnnotationConfigWebApplicationContext subContext = new AnnotationConfigWebApplicationContext();
    subContext.setParent(parentContext);
    subContext.register(BController.class);
    subContext.refresh();
    return subContext;
}

} `

`package b;

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;

/ * 测试 * * @author: Troy.Chen(無心道, 15388152619) * @version: 2024-07-30 20:57 / @Controller public class BController {

public BController() {
    System.out.println("BController");
}

@RequestMapping("/hello")
public String hello() {
    return "hello world";
}

} `

{ "timestamp": "2024-07-30T13:00:36.568+00:00", "status": 404, "error": "Not Found", "path": "/hello" }

使用AnnotationConfigWebApplicationContext 子容器希望通过 http://localhost:18801/hello 能访问路由

Comment From: snicoll

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.