您的位置:首页 > 财经 > 金融 > 宁波网站建设公司推荐哪家_北京软件设计公司_网络营销软文范例大全800_百度 官网

宁波网站建设公司推荐哪家_北京软件设计公司_网络营销软文范例大全800_百度 官网

2025/1/4 17:55:27 来源:https://blog.csdn.net/bohu83/article/details/144778343  浏览:    关键词:宁波网站建设公司推荐哪家_北京软件设计公司_网络营销软文范例大全800_百度 官网
宁波网站建设公司推荐哪家_北京软件设计公司_网络营销软文范例大全800_百度 官网

环境: jdk17

idea 2019

springboot:3.2.4

spring-cloud:2023.0.1

大概记录下关键配置

1 创建父工程

创建项目

删除src目录

因为是父子结构不需要。

引入依赖

<?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>org.tuling</groupId><artifactId>spring-cloud-alibaba-demo</artifactId><packaging>pom</packaging><version>${revision}</version><modules><module>order01</module></modules><name>spring-cloud-alibaba-demo</name><description>demo</description><!-- 项目依赖版本 --><properties><revision>1.0.0</revision><java.version>17</java.version><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><skipTests>true</skipTests><spring.boot.version>3.2.4</spring.boot.version><spring-cloud.version>2023.0.1</spring-cloud.version><spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version><spring.boot.test.version>3.2.4</spring.boot.test.version><lombok.version>1.18.30</lombok.version><flatten-maven-plugin.version>1.2.7</flatten-maven-plugin.version></properties><dependencyManagement><dependencies><!-- Spring Boot --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>${spring.boot.version}</version><type>pom</type><scope>import</scope></dependency><!-- Spring Cloud --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><!-- Spring Cloud Alibaba --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency><!-- spring-boot-starter-test --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><version>${spring.boot.test.version}</version></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version><optional>true</optional></dependency></dependencies></dependencyManagement><build><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring.boot.version}</version></plugin></plugins></pluginManagement></build><!-- 阿里云的Maven镜像源 --><repositories><repository><id>aliyunmaven</id><name>aliyun</name><url>https://maven.aliyun.com/repository/public</url></repository><repository><id>central2</id><name>central2</name><url>https://repo1.maven.org/maven2/</url></repository></repositories></project>

2 创建子模块(服务提供者)

新建module

引入依赖

<?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>spring-cloud-alibaba-demo</artifactId><groupId>org.tuling</groupId><version>1.0.0</version></parent><modelVersion>4.0.0</modelVersion><artifactId>order01</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Nacos注册中心 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><!-- <version>8.0.32</version> --></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version></dependency></dependencies><build><plugins><!-- 打包插件 --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins><!-- 将源码中的xml文件打包到jar中 --><resources><resource><directory>src/main/java</directory><excludes><exclude>**/*.java</exclude></excludes></resource><resource><directory>src/main/resources</directory><includes><include>**/*.*</include></includes></resource></resources></build></project>

3 添加配置文件

resources目录下新建 application.yml 配置文件,内容如下:

server:port: 8060spring:application:name: tlmall-order01cloud:nacos:discovery:server-addr: tlmall-nacos-server:8848#server-addr: nacos.tlmall.com:8848#namespace: fox  #指定为fox开发环境的命名空间#namespace: dev  # 指定注册到开发环境#cluster-name: SH  #上海机房username: nacospassword: nacosdatasource:url: jdbc:mysql://XXX:3306/tlmall_order?useSSL=false&characterEncoding=utf8&allowPublicKeyRetrieval=truedriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: 1234XXXXXmain:allow-bean-definition-overriding: true
mybatis:# 配置 mybatis 的xml文件的扫描路径mapper-locations: classpath:mybatis/**/*.xml# 配置实体类的扫描路径type-aliases-package: org.tuling.tlmallorder01.entityconfiguration:# 开启驼峰命名转换map-underscore-to-camel-case: true# 开启日志#log-impl: org.apache.ibatis.logging.stdout.StdOutImpllog-impl: org.apache.ibatis.logging.slf4j.Slf4jImplmanagement:endpoints:web:exposure:include: "*"

配置注意:数据源 

4 添加启动类

5 添加测试业务代码

controller

service

mapper

/resources/mybatis/ 目录下新增 XXMapper.xml 文件

 

CREATE TABLE `order` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`user_id` varchar(255) DEFAULT NULL,`commodity_code` varchar(255) DEFAULT NULL,`count` int DEFAULT NULL,`money` int DEFAULT '0',`create_time` datetime DEFAULT NULL,`update_time` datetime DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8mb3;

6 服务的测试

启动nacos.参见:nacos 让服务之间互相认识-CSDN博客

启动应用,测试接口

如果启动了nacos.观察下服务列表

注意下EndPoint,http://localhost:8060/actuator/nacosdiscovery

至此,springBoot的项目基本架构搭建成功。可以陆续添加其它子模块。主要是pom里面的配置,版本不一致可能产生的问题。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com