代码结构

包含mapper.xml的项目打成jar包供其他项目使用(sprinboot + mybatiPlus)

如何将mapper.xml文件打入jar包

在项目的pom.xml文件中包含如下代码即可:

<build>
    <finalName>项目名</finalName>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

如何方便别的系统引入并使用

  1. 写一个配置类:
@ComponentScan({"需要扫描的包目录"})
@MapperScan("需要扫描的mapper文件目录(xxMapper.java文件的目录)")
public class XxAutoConfiguration {
    public XxAutoConfiguration() {
    }
}
  1. 写一个快速引用类:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Import({XxAutoConfiguration.class})
@Documented
@Inherited
public @interface EnableXx {
}

打jar包

mvn clean package -Dmaven.test.skip=true

引入并使用该jar包

  1. 在主项目的pom.xml文件中引入该jar包
  2. 在主文件(XxApplication.java)中的相应位置写@EnableXx

相关文章:

  • 2022-01-01
  • 2021-11-28
  • 2021-08-01
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2021-06-28
  • 2021-12-12
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案