SpringBoot加载子模块配置文件的案例分析

  介绍

小编给大家分享一下SpringBoot加载子模块配置文件的案例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!

这两天开始学习SpringBoot框架,按照官方的文档,很轻易地就把单模块的项目启动了,但在使用maven搭建多模块的时候遇到了子模块配置文件没有加载的问题

项目架构是这样的

 0
  | - w
  |服务类型
  |刀
  |实体

0的依赖

& lt; dependencies>   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-web   & lt;/dependency>   & lt;/dependencies>

ws的依赖和配置

& lt; dependencies>   & lt; dependency>   & lt; groupId> cn.xmcui.zero   & lt; artifactId> service   & lt; version> 1.0 -snapshot   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-web   & lt;/dependency>   & lt;/dependencies>   & lt; build>   & lt; plugins>   & lt; plugin>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-maven-plugin   & lt; configuration>   & lt; !——指定该课程为全局唯一入口——比;   & lt; mainClass> cn.xmcui.zero.Application   & lt; fork> true   & lt; layout> ZIP   & lt;/configuration>   & lt; executions>   & lt; execution>   & lt; goals>   & lt; goal> repackage   & lt;/goals>   & lt;/execution>   & lt;/executions>   & lt;/plugin>   & lt;/plugins>   & lt;/build>

ws的应用程序。yml

服务器:
  端口:80
  servlet:
  会话:
  超时:60
  tomcat:
  uri编码:utf - 8 

dao的依赖和配置

& lt; dependencies>   & lt; dependency>   & lt; groupId> cn.xmcui.zero   & lt; artifactId> entity   & lt; version> 1.0 -snapshot   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.mybatis.spring.boot   & lt; artifactId> mybatis-spring-boot-starter   & lt; version> 1.3.2   & lt;/dependency>   & lt; dependency>   & lt; groupId> mysql   & lt; artifactId> mysql-connector-java   & lt; version> 5.1.47   & lt;/dependency>   & lt;/dependencies>

应用程序。yml

春:
  数据源:
  url: jdbc: mysql://localhost: 3306/零? useUnicode=true& characterEncoding=utf-8& useSSL=false
  用户名:根
  密码:根
  driver-class-name: com.mysql.jdbc.Driver
  mybatis:
  mapper-locations:类路径:映射器/* . xml
  type-aliases-package: cn.xmcui.zero。实体

给启动器类加注解

@SpringBootApplication (scanBasePackages=癱n.xmcui.zero")   @MapperScan (basePackages=癱n.xmcui.zero.mapper")   公共类应用程序{   公共静态void main (String [] args) {   SpringApplication.run (Application.class, args);   }   }

运行

然后是喜闻乐见的报错

* * * * * * * * * * * * * * * * * * * * * * * * * * *   应用程序没有启动   ***************************      描述:      没有配置数据源:& # 39;url # 39;没有指定属性,没有嵌入的数据源可以配置。      原因:未能确定一个合适的驱动程序类         行动:      考虑以下:   如果你想要一个嵌入式数据库(H2, HSQL或Derby),请把它>春:   配置文件:   活动:刀,dev

这条配置是指定加载哪些配置文件

操作完成,系统成功点亮

本来是很简单的问题,却浪费了我很长的时间,还有一件事情必须要吐槽一下,现在SpringBoot相关的博客质量真是良莠不齐,相当数量的人还是把它当SpringMvc用;使用它,却不用它的新特性,真的是毫无意义啊。

以上是SpringBoot加载子模块配置文件的案例分析的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

SpringBoot加载子模块配置文件的案例分析