1 说明
- 全部配置基于
1.8.0_111
- 当前SpringBoot使用
2.0.5
2 创建项目
在SpringBoot项目生成器中,输入Group
和Artifact
,如下配置:
3 pom.xml配置
pom.xml文件中,加入以下:
<properties>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
4 配置application.yml文件
修改application.properties
为application.yml
文件,加入以下:
server:
port: 8888
spring:
application:
name: eurka-server
security:
user:
name: anxminise
password: 123456
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@127.0.0.1:${server.port}/eureka/
5 编辑SpringBootEurekaApplication.java文件
编辑SpringBootEurekaApplication.java
,如下:
@EnableEurekaServer
@SpringBootApplication
public class SpringBootEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootEurekaApplication.class, args);
}
@EnableWebSecurity
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
super.configure(http);
}
}
}
6 启动eureka
执行以下命令,进行构建并启动:
./mvnw clean package -DskipTests #构建可直接运行的jar包
java -jar target/SpringBootEureka-0.0.1-SNAPSHOT.jar #启动jar包