首页 > 编程语言 > 详细

【springcloud】springcloud Greenwich SR4版本笔记

时间:2019-12-03 23:04:58      阅读:205      评论:0      收藏:0      [点我收藏+]

springcloud Greenwich SR4版本笔记

  本文只记录实际版本,配置,pom,代码以及注意事项。别的在其他springcloud 的F版本中已有详述。

目录:

  1. eureka server

 

 

1. eureka server

1.1 版本选择

jdk:    1.8
springcloud:    Greenwich.SR4
springboot:    2.1.9.RELEASE

1.2 pom

1.2.1 项目父pom

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.9.RELEASE</version>
  </parent>
  
  <modules>
  	<module>finchley-sr4-eureka-server</module>
  </modules>
  
  <properties>
  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>
  
  <dependencyManagement>
  	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>Greenwich.SR4</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
  	</dependencies>
  </dependencyManagement>
  
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

1.2.2 eureka server pom

<dependencies>
  	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
	</dependency>
  </dependencies>

1.3 配置

1.3.1 单节点配置

application.yml中配置如下:

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

1.4 代码

eureka server 中起动类代类如下:

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
  
    public static void main(String[] args) {
    	SpringApplication.run(EurekaServerApplication.class, args);
    }
}

1.5 安全校验

1.5.1 pom增加项

        <dependency>
  		<groupId>org.springframework.boot</groupId>
  		<artifactId>spring-boot-starter-security</artifactId>
  	</dependency>    

1.5.2 eureka server

配置修改如下

server:
  port: 8761
  
user: huaxia
password: huaxia 
  
spring:
  security:
    user:
      name: ${user}
      password: ${password}
  
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${user}:${password}@{eureka.instance.hostname}:${server.port}/eureka/

1.5.3 eureka client 

配置时修改如下

eureka:
  client:
    service-url:
      defaultZone:http://${user}:${password}@{eureka.instance.hostname}:${server.port}/eureka/

1.5.4 注意项

  由于默认是开启CSRF,所以需要将其关闭,不然会出现如下错误:

javax.ws.rs.WebApplicationException: com.fasterxml.jackson.databind.exc.MismatchedInputException: 
Root name ‘timestamp‘ does not match expected (‘instance‘) for type [simple type, class com.netflix.appinfo.InstanceInfo]

  创建一个WebSecurityConfig类,代码如下:

// WebSecurityConfig.java
 
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable(); //关闭csrf
        super.configure(http); //开启认证
    }
}
 

  

安全配置参考:https://blog.csdn.net/wgh100817/article/details/101719042

 

 

 

  

【springcloud】springcloud Greenwich SR4版本笔记

原文:https://www.cnblogs.com/wjqhuaxia/p/11979971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!