您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

我们可以使用Spring Boot来实现Java库吗?

我们可以使用Spring Boot来实现Java库吗?

如果以正确的方式进行设计,这根本不是问题。但是,具体取决于您使用的功能。由于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扫描。

java 2022/1/1 18:13:36 有623人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶