springboot引入其他项目jar包,jar使用当前项目的数据库配置文件

2021/8/9 19:06:20

本文主要是介绍springboot引入其他项目jar包,jar使用当前项目的数据库配置文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、在当前项目中创建lib目录,放入第三方jar包

2、在pom文件中引入jar包

  <dependency>
            <groupId>com.myjar</groupId>
            <artifactId>com.myjar</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/myjar.jar</systemPath>
        </dependency>

  

 <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 引入外部jar包,打包时需要设置的 -->
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>

 3、在启动类中以注解的形式将jar中的mapper、service、controller注入到当前项目的spring容器中

@SpringBootApplication
//将myjar的dao到本项目中,如果myjar,xml位置不是com.example.demo01.dao,需要在配置文件中指明路径
//demo01是myjar中的,demo02是当前项目
@MapperScan({"com.example.demo01.dao","com.example.demo02.dao"})
//将myjar的service、controller注入到本项目中
@ComponentScan({"com.example.demo01.service","com.example.demo02"})
public class Demo02Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo02Application.class, args);
    }

}

  



这篇关于springboot引入其他项目jar包,jar使用当前项目的数据库配置文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程