spring.xml一片红,子项目依赖不生效
为什么在子项目中配置的依赖并没有生效?拿老师的源码打开也一样
实测在父项目中配置依赖就可以。
请问如何解决?
父项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < groupId >com.mike</ groupId > < artifactId >mySystem</ artifactId > < packaging >pom</ packaging > < version >1.0-SNAPSHOT</ version > < modules > < module >myService</ module > < module >myWeb</ module > </ modules > </ project > |
子项目-1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < parent > < artifactId >mySystem</ artifactId > < groupId >com.mike</ groupId > < version >1.0-SNAPSHOT</ version > </ parent > < modelVersion >4.0.0</ modelVersion > < artifactId >myService</ artifactId > < packaging >jar</ packaging > < dependencies > <!--数据库相关--> < dependency > < groupId >mysql</ groupId > < artifactId >mysql-connector-java</ artifactId > < version >8.0.18</ version > </ dependency > < dependency > < groupId >org.mybatis</ groupId > < artifactId >mybatis</ artifactId > < version >3.5.3</ version > </ dependency > <!--Spring相关--> < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-core</ artifactId > < version >4.2.4.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-beans</ artifactId > < version >4.2.4.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-context</ artifactId > < version >4.2.4.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-aop</ artifactId > < version >4.2.4.RELEASE</ version > </ dependency > < dependency > < groupId >org.aspectj</ groupId > < artifactId >aspectjweaver</ artifactId > < version >1.9.5</ version > </ dependency > <!--事务相关--> < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-jdbc</ artifactId > < version >4.2.4.RELEASE</ version > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-tx</ artifactId > < version >4.2.4.RELEASE</ version > </ dependency > < dependency > < groupId >org.mybatis</ groupId > < artifactId >mybatis-spring</ artifactId > < version >1.3.1</ version > </ dependency > </ dependencies > </ project > |
子项目-2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < parent > < artifactId >mySystem</ artifactId > < groupId >com.mike</ groupId > < version >1.0-SNAPSHOT</ version > </ parent > < modelVersion >4.0.0</ modelVersion > < artifactId >myWeb</ artifactId > < dependencies > < dependency > < groupId >com.mike</ groupId > < artifactId >myService</ artifactId > < version >1.0-SNAPSHOT</ version > </ dependency > < dependency > < groupId >javax.servlet</ groupId > < artifactId >javax.servlet-api</ artifactId > < version >4.0.1</ version > </ dependency > < dependency > < groupId >javax.servlet</ groupId > < artifactId >jstl</ artifactId > < version >1.2</ version > </ dependency > </ dependencies > </ project > |
30
收起
正在回答
4回答
同学你好!
按以下步骤试一下:
1. 打开IDEA右侧的侧边栏Maven Project -> lifecycle -> clean
2. install
3. 最后同样是在Maven Project 侧边栏中,右键项目名称 -> reimport
4. 如果不可以,找到项目在本地的路径,将项目下面的 .idea 文件删除,重新导入项目测试一下
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
宝慕林0551093
2020-01-02 18:59:00
在子Maven有依赖,可是external libraries里没有jar包,而且xml中也不能导入需要类;重新导入也不行;重新新建项目也不行;只能将依赖放在父项目是唯一的可行方式
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧