Authored by zhengyouwei

add

@@ -9,11 +9,10 @@ @@ -9,11 +9,10 @@
9 </parent> 9 </parent>
10 <modelVersion>4.0.0</modelVersion> 10 <modelVersion>4.0.0</modelVersion>
11 11
12 - <artifactId>monitor-ui-service</artifactId> 12 + <artifactId>monitor-ui-common</artifactId>
13 <version>1.0-SNAPSHOT</version> 13 <version>1.0-SNAPSHOT</version>
14 - <dependencies>  
15 14
16 - <!-- 需要的Spring Framework jar包 --> 15 + <dependencies>
17 <dependency> 16 <dependency>
18 <groupId>org.springframework</groupId> 17 <groupId>org.springframework</groupId>
19 <artifactId>spring-webmvc</artifactId> 18 <artifactId>spring-webmvc</artifactId>
@@ -67,7 +66,12 @@ @@ -67,7 +66,12 @@
67 <groupId>com.fasterxml.jackson.core</groupId> 66 <groupId>com.fasterxml.jackson.core</groupId>
68 <artifactId>jackson-databind</artifactId> 67 <artifactId>jackson-databind</artifactId>
69 </dependency> 68 </dependency>
70 - 69 + <dependency>
  70 + <groupId>commons-lang</groupId>
  71 + <artifactId>commons-lang</artifactId>
  72 + <version>2.6</version>
  73 + </dependency>
71 </dependencies> 74 </dependencies>
72 75
  76 +
73 </project> 77 </project>
  1 +package com.ui.config;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +@Component("config")
  7 +public class SystemConfig {
  8 +
  9 + /**
  10 + * 系统环境
  11 + */
  12 + @Value("${monitor.service.url}")
  13 + private String serviceUrl;
  14 +
  15 + public String getServiceUrl() {
  16 + return serviceUrl;
  17 + }
  18 +
  19 + public void setServiceUrl(String serviceUrl) {
  20 + this.serviceUrl = serviceUrl;
  21 + }
  22 +}
  1 +package com.ui.contants;
  2 +
  3 +/**
  4 + * Created by zhengyouwei on 2016/6/14.
  5 + */
  6 +public class HttpUriContants {
  7 +
  8 + public static String TEST_GET_URI = "/test/get";
  9 +
  10 +}
1 -package com.ui.service.impl; 1 +package com.ui.http;
2 2
3 -import com.ui.service.HttpRestClientService; 3 +import com.ui.config.SystemConfig;
4 import org.slf4j.Logger; 4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
8 import org.springframework.web.client.RestTemplate; 8 import org.springframework.web.client.RestTemplate;
9 9
10 -import java.util.Map;  
11 -  
12 -@Service("httpRestClientService")  
13 -public class HttpRestClientServiceImpl implements HttpRestClientService { 10 +public class HttpRestClient {
14 11
15 private static final Logger logger = LoggerFactory 12 private static final Logger logger = LoggerFactory
16 - .getLogger(HttpRestClientServiceImpl.class); 13 + .getLogger(HttpRestClient.class);
17 14
18 - @Autowired  
19 private RestTemplate restTemplate; 15 private RestTemplate restTemplate;
20 16
21 - @Override  
22 - public <T> T postForObject(String url, Object request, Class<T> responseType) { 17 + private SystemConfig systemConfig;
  18 +
  19 + public <T> T defaultPost(String uri, Object request, Class<T> responseType) {
23 try { 20 try {
24 - return restTemplate.postForObject(url, request,responseType); 21 + return restTemplate.postForObject(systemConfig.getServiceUrl() + uri, request,responseType);
25 } catch (Exception e) { 22 } catch (Exception e) {
26 - logger.error("postForObject failed!url:"+url, e); 23 + logger.error("postForObject failed!url:"+uri, e);
27 return null; 24 return null;
28 } 25 }
29 } 26 }
30 27
  28 + public void setRestTemplate(RestTemplate restTemplate) {
  29 + this.restTemplate = restTemplate;
  30 + }
  31 + public void setSystemConfig(SystemConfig systemConfig) {
  32 + this.systemConfig = systemConfig;
  33 + }
31 } 34 }
@@ -38,5 +38,11 @@ @@ -38,5 +38,11 @@
38 </property> 38 </property>
39 </bean> 39 </bean>
40 40
  41 + <bean id="systemConfig" class="com.ui.config.SystemConfig" />
  42 +
  43 + <bean id="httpRestClient" class="com.ui.http.HttpRestClient">
  44 + <property name="restTemplate" ref="restTemplate"/>
  45 + <property name="systemConfig" ref="systemConfig"/>
  46 + </bean>
41 47
42 </beans> 48 </beans>
@@ -15,64 +15,7 @@ @@ -15,64 +15,7 @@
15 <dependencies> 15 <dependencies>
16 <dependency> 16 <dependency>
17 <groupId>monitor-ui</groupId> 17 <groupId>monitor-ui</groupId>
18 - <artifactId>monitor-ui-service</artifactId>  
19 - </dependency>  
20 - <dependency>  
21 - <groupId>org.springframework</groupId>  
22 - <artifactId>spring-webmvc</artifactId>  
23 - </dependency>  
24 - <dependency>  
25 - <groupId>org.springframework</groupId>  
26 - <artifactId>spring-web</artifactId>  
27 - </dependency>  
28 - <dependency>  
29 - <groupId>org.springframework</groupId>  
30 - <artifactId>spring-oxm</artifactId>  
31 - </dependency>  
32 - <dependency>  
33 - <groupId>org.springframework</groupId>  
34 - <artifactId>spring-core</artifactId>  
35 - </dependency>  
36 - <dependency>  
37 - <groupId>org.springframework</groupId>  
38 - <artifactId>spring-aop</artifactId>  
39 - </dependency>  
40 - <dependency>  
41 - <groupId>org.springframework</groupId>  
42 - <artifactId>spring-context-support</artifactId>  
43 - </dependency>  
44 - <dependency>  
45 - <groupId>org.springframework</groupId>  
46 - <artifactId>spring-jdbc</artifactId>  
47 - </dependency>  
48 - <dependency>  
49 - <groupId>org.aspectj</groupId>  
50 - <artifactId>aspectjweaver</artifactId>  
51 - </dependency>  
52 - <dependency>  
53 - <groupId>org.slf4j</groupId>  
54 - <artifactId>slf4j-api</artifactId>  
55 - </dependency>  
56 - <dependency>  
57 - <groupId>ch.qos.logback</groupId>  
58 - <artifactId>logback-classic</artifactId>  
59 - <scope>runtime</scope>  
60 - </dependency>  
61 - <dependency>  
62 - <groupId>commons-lang</groupId>  
63 - <artifactId>commons-lang</artifactId>  
64 - <version>2.6</version>  
65 - </dependency>  
66 - <dependency>  
67 - <groupId>com.alibaba</groupId>  
68 - <artifactId>fastjson</artifactId>  
69 - <version>1.2.7</version>  
70 - </dependency>  
71 - <dependency>  
72 - <groupId>junit</groupId>  
73 - <artifactId>junit</artifactId>  
74 - <version>3.8.1</version>  
75 - <scope>test</scope> 18 + <artifactId>monitor-ui-common</artifactId>
76 </dependency> 19 </dependency>
77 </dependencies> 20 </dependencies>
78 </project> 21 </project>
1 package com.ui.ctrl.test; 1 package com.ui.ctrl.test;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 -import com.ui.service.HttpRestClientService; 4 +import com.ui.contants.HttpUriContants;
  5 +import com.ui.http.HttpRestClient;
5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Controller; 7 import org.springframework.stereotype.Controller;
7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.RequestMapping;
@@ -18,14 +19,14 @@ import java.util.Map; @@ -18,14 +19,14 @@ import java.util.Map;
18 public class TestCtrl { 19 public class TestCtrl {
19 20
20 @Autowired 21 @Autowired
21 - private HttpRestClientService httpRestClientService; 22 + private HttpRestClient httpRestClient;
22 23
23 @RequestMapping("test") 24 @RequestMapping("test")
24 @ResponseBody 25 @ResponseBody
25 public OrderInfoCheck test(){ 26 public OrderInfoCheck test(){
26 Map map = new HashMap(); 27 Map map = new HashMap();
27 map.put("id",1); 28 map.put("id",1);
28 - OrderInfoCheck result = httpRestClientService.postForObject("http://localhost:8081/monitor/test/get",map,OrderInfoCheck.class); 29 + OrderInfoCheck result = httpRestClient.defaultPost(HttpUriContants.TEST_GET_URI, map, OrderInfoCheck.class);
29 return result; 30 return result;
30 } 31 }
31 } 32 }
1 -package com.ui.service;  
2 -  
3 -import java.util.Map;  
4 -  
5 -public interface HttpRestClientService {  
6 -  
7 - public <T> T postForObject(String url, Object request, Class<T> responseType);  
8 -  
9 - }  
  1 +monitor.service.url=http://127.0.0.1:8080/monitor
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 </dependency> 57 </dependency>
58 <dependency> 58 <dependency>
59 <groupId>monitor-ui</groupId> 59 <groupId>monitor-ui</groupId>
60 - <artifactId>monitor-ui-service</artifactId> 60 + <artifactId>monitor-ui-common</artifactId>
61 <version>${project-version}</version> 61 <version>${project-version}</version>
62 </dependency> 62 </dependency>
63 </dependencies> 63 </dependencies>
@@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
67 <modules> 67 <modules>
68 <module>monitor-ui-web</module> 68 <module>monitor-ui-web</module>
69 <module>monitor-ui-ctrl</module> 69 <module>monitor-ui-ctrl</module>
70 - <module>monitor-ui-service</module> 70 + <module>monitor-ui-common</module>
71 </modules> 71 </modules>
72 72
73 73