[英]How to import gis shapefiles into postgis database programatically?
[英]How to force the import/loading of rest controller programatically
我正在啟動一個Spring Boot Rest服務,該服務可能會根據發行版本加載不同的軟件包。 這意味着有時發行版將在某些REST控制器所在的位置包含一些jar,有時此控制器不存在。
因此,我如何告訴spring-boot在哪里可以找到帶有配置文件的控制器。 現在,我通過注釋發送此信息,迫使我為每個發行版創建一個“主”。 我想定義一個唯一的主體,該主體可以導入文件中定義的控制器。 換句話說,我想手動訪問@Import
批注,如下面的波紋管所示:
@Configuration
@PropertySource("conf.cfg")
@Import(value = {RestContorller1.class, RestContorller2.class})
@EnableAutoConfiguration
@ConfigurationProperties
@SpringBootApplication
@RestController
@EnableSwagger2
public class Application {
public static void main(String[] args) {
String confFile = Const.DEFAULT_CONFIGURATION_FILE;
if(args.length>0)
confFile= args[0];
System.setProperty("spring.config.name",confFile);
Boolean hasStarted = DataProcessingCore.start(confFile);
if(hasStarted) {
SpringApplication springApp = new SpringApplication(Application.class);
try {
springApp.setDefaultProperties(Utils.createPropertyFiles(confFile));
} catch (IOException e) {
e.printStackTrace();
}
springApp.addInitializers();
springApp.run(args);
}
}
}
如果我正確理解您的觀點,那么您的控制器就位於由maven
/ gradle
導入到您的主項目中的JAR中。
為了像spring boot一樣創建auto-configuration
,當jar放在類路徑中時,可以用相同的方式導入控制器,您可以告訴spring在啟動時找到您的自定義configuration
。
我在這里寫了一個簡單的例子: 創建自己的自動配置
首先,您將創建一個spring-boot應用程序(沒有spring boot maven插件!對於類路徑和打包很重要)。 並創建一個名為spring.factories
的文件(您可以在我鏈接的指南中找到實際內容),該文件告訴具有該jar的任何spring-boot應用程序可以加載您的配置,可以使用@ComponentScan
來搜索您的控制器或設置@Bean
手動。
這樣做,您不必執行@Import
,控制器將被動態加載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.