spring cloud same strain Ⅰ-eureka articles Practice

Green Zijin, Youyouwoxin That year spring, and spring raglan me through, perhaps from not goodbye, perhaps even meet. I was hit by an arrow in the spring on career planning courses our instructor name of discipline, character Goldwater autumn. I was slow reaction is known, also due to slow reaction fined copying spring mvc 10 times. Since then, spring rely on me not to go, he let me finish and a sister seniors graduation project, also completed my own graduation. after graduation, first job is to use spring mvc mybatis. boot time has perhaps not yet. when I see someone still using Struts series, I its bloated laugh, laugh at him repeatedly configuration. this may also doomed I spotted early spring of this family. but what really made me go clawed source that cloud the .cloud let me use a shorter time complete the superior things. Unfortunately, it is still only used on my personal project has nothing to do with the company and now I upgrade project, combined with the separation of the front and rear end vue just learning. there are some technical database fragmentation I successfully used bolder obey my ambition. go Personally buried under the two cloud tree, starting today reopened autopsy. So return visit, the basics.

(A) with sts build your own maven project

New results file delete unnecessary FIG inside:
Here Insert Picture Description
Configuration pox.xml follows:

<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>cn.com.css.cloud</groupId>
	<artifactId>css-cloud</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>

	<name>css-cloud</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<!-- 建议用1.4.0以后的版本之前的不能可能导致部分功能不能使用 包冲突 会出现注册问题 -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.1.RELEASE</version>
	</parent>
	<modules>
		<module>css-cloud-server</module><!--注册中心项目 -->
	</modules>
	<!-- spring-cloud所有项目依赖包 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Dalston.SR1</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<scope>test</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
</project>

(B) maven project on top of a new module

New results were as follows:
Here Insert Picture Description
pox.xml configured as follows:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>cn.com.css.cloud</groupId>
    <artifactId>css-cloud</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>css-cloud-server</artifactId>
  <name>css-cloud-server</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
     </dependency>
     <dependency>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-security</artifactId>
	</dependency>
	<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
  <build>
	<finalName>css-cloud-server</finalName>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<executions>
				<execution>
					<goals>
						<goal>repackage</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<encoding>utf-8</encoding>
				<source>1.8</source>
				<target>1.8</target>
			</configuration>
		</plugin>
	</plugins>
  </build>
</project>

Startup class configuration as follows:

package org.css.cloud.server;

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

@SpringBootApplication // spring-boot 启动注解
@EnableEurekaServer // spring-cloud 服务注解
public class App {
	public static void main(String[] args) {
		new SpringApplicationBuilder(App.class).web(true).run(args);
	}
}

New resource file as follows:
Here Insert Picture Description
application.yml contents of the file:

spring:
  profiles:
    #默认指向开发配置 application-dev.yml
    active: dev
  application:
    name: css_cloud_server

dev-yml contents of the file:

server:
  port:  9090

security: 
  basic: 
    enabled: true
  user: 
    name: ljq
    password: 123456
    
eureka:
  instance:
    #服务注册中心实例的主机名
    hostname: master
  client:
    #是否向服务注册中心注册自己
    register-with-eureka: false
    #是否检索服务
    fetch-registry: false
    service-url:
      #defaultZone: http://${security.user.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/
      defaultZone: http://${security.user.name}:${security.user.password}@slave:9091/eureka/
  server:
    #是否打开注册中心的保护机制
    enable-self-preservation: false
    

(C) start

Enter in your browser http: // localhost: 9090 /
to enter a user name and secret, Eau:
Here Insert Picture Description
In this way, the service registry is not doing a good job so easy now!!

Summary
from the operation of the interface, we see the registry, but not the service provider and the service registered party, it does not matter, we will follow to add Vaga brick.

Published 17 original articles · won praise 4 · Views 4808

Guess you like

Origin blog.csdn.net/qq_15054679/article/details/89282143