背景
我有许多小型微服务类型的应用程序,它们都使用@RestController& amp; @RequestMapping。由于他们通常是互相交谈,因此我通过HTTP提供了每个JAR,但我也可以在其他项目中包含每个JAR以直接访问其功能。这已成为一个问题;因为JAR的映射在它启动时被映射到宿主应用程序中......在我看来这将是一个安全问题。
是否可以阻止某些映射被Spring加载?
答案 0 :(得分:0)
这是我不时使用的食谱:
在依赖关系jar中,创建一个配置类:
package com.example.dependency;
@Configuration
@ComponentScan("com.example.dependency")
public class DependencyConfig {
// possibly return other @Bean declarations
}
在Spring Boot应用程序中(在另一个jar中),您可以@Import
依赖配置:
package com.example.application;
@SpringBootApplication
@Import(DependencyConfig.class)
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
好处是MainApplication
不需要知道它需要扫描哪个依赖包,它是隐藏在依赖jar中的实现细节。