Spring cloud 简单的将将项目打包为jar 并运行

一、准备一个maven项目,将maven jdk等环境配置好。

二、项目结构如图所示

Spring cloud 简单的将将项目打包为jar 并运行_第1张图片

三、pom.xml添加 


        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            repackage
                        
                    
                
            
        
    
四、pom.xml文件

    
        yanlz-test-providercus
        yanlz.test.cloud
        1.0-SNAPSHOT
    
    4.0.0

    yanlz-test-config-eureka
    jar

    yanlz-test-config-eureka
    http://maven.apache.org

    
        UTF-8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.cloud
            spring-cloud-starter-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-security
        
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            repackage
                        
                    
                
            
        
    
 
  

  五、java类

package yanlz.test.config.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * @version 1.0
 * @Title: Eureka 服务
 * @Description:
 * @Author: yanlz
 * @Date: Create By 2018/3/11 2:01
 * @Modyfied By:
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaAppliction {
    public static void main( String[] args ) {
        SpringApplication.run(EurekaAppliction.class,args);
    }
}

六、配置文件

server:
  port: 8761

security:
  basic:
    enabled: true
  user:
    name: admin
    password: admin123
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://admin:admin123@localhost:8761/eureka
  dashboard:
    enabled: true #关闭主界面
    path:  /yanlz
  #修改eureka主界面 System Status的两个参数
  datacenter: cloud
  environment: product
spring:
  application:
    name: yanlz-test-config-eureka
七、执行mvn命令  mvn install  如图

Spring cloud 简单的将将项目打包为jar 并运行_第2张图片

见到 BUILD SUCCESS

Spring cloud 简单的将将项目打包为jar 并运行_第3张图片

八、执行 java -jar target\yanlz-test-config-eureka-1.0-SNAPSHOT.jar

Spring cloud 简单的将将项目打包为jar 并运行_第4张图片

你可能感兴趣的:(spring,cloud,spring,boot)