springboot springcloud zuul 网关入门


1.配置

2.使用

1.配置


org.springframework.cloud
spring-cloud-starter-netflix-zuul

   main函数注解:

@EnableZuulProxy

#zuul配置
zuul.routes.common.path=/common/**
zuul.routes.common.service-id=demo-common
zuul.routes.student.path=/student/**
zuul.routes.student.service-id=demo-student
zuul.routes.teacher.path=/teacher/**
zuul.routes.teacher.service-id=demo-teacher


工程pom
<?xml version="1.0" encoding="UTF-8"?>

         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">
    4.0.0

    com.ligy
    demo-school
    pom
    1.0-SNAPSHOT
    
        demo-common
        demo-student
        demo-teacher
        demo-eurekaserver
        demo-zuul
    

    
        1.8
        UTF-8
        UTF-8
        2.3.7.RELEASE
        Hoxton.SR9
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
            
                org.springframework.boot
                spring-boot-dependencies
                ${spring-boot.version}
                pom
                import
            
        
    

common模块pom

<?xml version="1.0" encoding="UTF-8"?>

         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">
    
        demo-school
        com.ligy
        1.0-SNAPSHOT
    
    4.0.0

    demo-common

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
            2.2.6.RELEASE
        
        
            org.springframework.cloud
            spring-cloud-starter-openfeign
        
    

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

zuul模块pom

<?xml version="1.0" encoding="UTF-8"?>

         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">
    
        demo-school
        com.ligy
        1.0-SNAPSHOT
    
    4.0.0

    demo-zuul

    
        
            com.ligy
            demo-common
            1.0-SNAPSHOT
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-zuul
        
    

 

2.使用

模块common测试接口:

localhost:9001/test

localhost:10000/common/test

 

模块demo-eurekaserver