mall商城笔记-02

发布时间 2024-01-11 22:06:14作者: his365

项目的搭建

一、搭建父工程

  • 这里要注意父工程的boot版本与cloud版本的对照,否则无法启动
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-parent</artifactId>
	<version>3.2.1</version>
</parent>

<!--springcloud的版本控制-->
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>2023.0.0</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

二、搭建Eureka

  1. 添加依赖
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

  1. 开启服务
@SpringBootApplication
@EnableEurekaServer // 开启Eureka服务
public class EurekaApplication
{
    public static void main( String[] args )
    {
        SpringApplication.run(EurekaApplication.class,args);
    }
}
  1. 配置文件
server:
  port: 7001
eureka:
  instance:
    hostname: 127.0.0.1
  client:
    register-with-eureka: false   #是否将自己注册到eureka中
    fetch-registry: false         #是否从eureka中获取信息
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
  application:
    name: eureka
  1. 网页访问
    http://127.0.0.1:7001/