谷粒商城 day2
代码生成器
git clone https://gitee.com/renrenio/renren-generator.git
随后修改yml文件里的配置信息,运行java。
访问成功后,可以逆向生成相关的java代码。
生成的类,还不能够使用,有需要 mybatis-plus的,有需要 renren 自己东西的。
权限框架,这里也需要换成 spring security。
创建一个独立的module,在这里写所有的被依赖的文件,然后所有的其他模块都依赖这个模块。
<dependency>
<groupId>com.tifa.gulimall</groupId>
<artifactId>gulimall-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
这个逆向工程很繁琐,复制粘贴的。新版的代码与之前的有略微的不同。
在其他模块添加此依赖后,报错:
[ERROR] Failed to execute goal on project gulimall-product: Could not resolve dependencies for project com.tifa.gulimall:gulimall-product:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.tifa.gulimall:gulimall-common:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.tifa.gulimall:gulimall-common:jar:0.0.1-SNAPSHOT: Could not find artifact com.tifa.gulimall:gulimall:pom:0.0.1-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
进程已结束,退出代码1
原因:引入Mybatis Plus 依赖后,必须进行配置 application.tml 。同时注意,数据库链接的用户名称必须是 username,而非name。
在product中配置 Mybatis-plus
不明白,在common中配置了这个诶。- 所以不用管这个了。直接配置数据库驱动。
spring:
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:7789/gulimall_pms
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
配置完成后,在Test类中写代码,但是遇到了一些问题:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'attrAttrgroupRelationService': Unsatisfied dependency expressed through field 'baseMapper': No qualifying bean of type 'com.tifa.gulimall.product.dao.AttrAttrgroupRelationDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
原因是 myabtis plus 不兼容 spring boot 3.0,需要升级 mp 到 3.5.3 之后的才行。
为不同的微服务设置不同的端口
将不同的微服务设置的端口,例如order设置为9000,product设置为10000。这样比如order相关的多了一个服务,那么90系的端口,就都是order相关的。