如果以正确的方式进行设计,这根本不是问题。但是,具体取决于您使用的功能。由于Spring支持外部库,例如JPA,Websocket等。
第一个是,简单@Configuration
的是@Import
。
将一个类放在根包中,看起来像这样。
@Configuration // allows to import this class
@ComponentScan // Scan for beans and other configuration classes
public class SomeLibrary {
// no main needed here
}
通常,将一个类放在项目的根包中。
@SpringBootApplication
@Import(SomeLibrary.class) // import the library
public class OtherApplication {
// just put your standard main in this class
}
重要的是要记住,根据您在其他框架上的使用情况,可能还需要执行其他操作。例如,如果您使用 spring-data, 则@EntityScan
注释会扩展hibernate扫描。