Metrics
0
Watch 163 Star 471 Fork 185

vakinge / oneplatformJavaApache-2.0

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
onePlatform企业级开发平台,基于springcloud2.x+jeesuite-libs构建。合理性、实用性、易用性秒杀90%开源的所谓的企业级开发平台。持续关注请star,学习请加群陆续将推出视频教程。 spread retract

http://oneplatform.jeesuite.com/

  • Java 61.5%
  • JavaScript 18.2%
  • HTML 14.7%
  • CSS 5.5%
  • Dockerfile 0.1%
Clone or download
old-system-guide.md 2.10 KB
Copy Edit Web IDE Raw Blame History
vakinge authored 2018-05-27 17:10 . +

使用案例

一个传统jersey的web项目接入Springcloud例子

以下是详细步骤

新增依赖

<dependency>
	<groupId>com.jeesuite</groupId>
	<artifactId>oneplatform-base</artifactId>
	<version>1.0.0</version>
</dependency>

添加eureka配置

#全局配置
eureka.region=default
eureka.registration.enabled=true
eureka.preferIpAddress=true
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://superms:superms2018@eureka.jeesuite.com/eureka/
eureka.decoderName=JacksonJson


#应用配置
server.port=8080
eureka.name=jerseydemo
eureka.vipAddress=${eureka.name}
eureka.port=${server.port}
eureka.ipAddr=${spring.cloud.client.ipAddress}
eureka.instanceId=${spring.cloud.client.ipAddress}:${server.port}/${eureka.name}
eureka.homePageUrl=http://${spring.cloud.client.ipAddress}:${eureka.port}
eureka.healthCheckUrl=http://${spring.cloud.client.ipAddress}:${eureka.port}/service/health
eureka.statusPageUrl=http://${spring.cloud.client.ipAddress}:${eureka.port}/service/info

说明

  • spring.cloud.client.ipAddress:默认读取本机ip

配置web.xml

替换ContextLoaderListener(已经包含日志初始化等)

<listener>
  <listener-class>com.oneplatform.base.spring.ContextLoaderListener</listener-class>
</listener>

增加服务检查servlet

<servlet>
   <servlet-name>ServiceCheckServlet</servlet-name>
   <servlet-class>com.oneplatform.base.servlet.ServiceCheckServlet</servlet-class>
</servlet>
<servlet-mapping>
   <servlet-name>ServiceCheckServlet</servlet-name>
   <url-pattern>/service/*</url-pattern>
</servlet-mapping>

通过eureka调用服务


  private RestTemplate restTemplate = EurekaRestTemplateBuilder.build();

  public List<IdNamePair> getProvinces() {
    ParameterizedTypeReference<List<IdNamePair>> arearesponseType = new ParameterizedTypeReference<List<IdNamePair>>() {
    };
    List<IdNamePair> lists = restTemplate
        .exchange("http://COMMON-SERVICE/region/provinces", HttpMethod.GET, null, arearesponseType)
        .getBody();
    return lists;
  }

Comment ( 1 )

You need to Sign in for post a comment

Help Search