我正在尝试使用 Zuul 和 Consul 创建一个 Spring 云微服务应用程序。
我的项目中有 2 个组件:
使用 Zuul 的 api-gateway 微服务
Hello world 微服务(一个简单的 hello world Rest Webservice)
这是 api-gateway 的代码:
@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.M3</version>
</parent>
<properties>
<java.version>1.8</java.version>
<spring.cloud.consul.version>1.0.0.M4</spring.cloud.consul.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> …Run Code Online (Sandbox Code Playgroud) 我正在尝试为本地主机中部署的许多 Web 服务添加受信任的证书。\n我找到这篇文章: http ://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification -path-to-requested-target/ \n当您按照本文中的步骤操作时,结果将是 \xe2\x80\x9cjssecacerts\xe2\x80\x9d 文件。\n就我而言,我有很多服务器:
\n\n因此,我尝试生成两个不同的文件,名为 \xe2\x80\x9cjssecacerts_8181\xe2\x80\x9d 和 \xe2\x80\x9cjssecacerts_8282\xe2\x80\x9d。但这个不行。
\n\n生成的文件名是否必须是“jssecacerts”?\n 如何添加多个可信证书?
\n我有2个清单:
鉴于list1的大小与list2相同
我想迭代list2,如果list2的name2不为null,则更新list1的name1.
这是使用旧java的代码:
for(Object1 obj1:list1) {
for(Object2 obj2:list2) {
if(obj1.getId1.equals(obj2.getId2)) {
obj1.setName1(obj2.getName2);
}
}
}
Run Code Online (Sandbox Code Playgroud)
哪个是用java.util.stream实现这个的最好方法?
我喜欢在没有领事的情况下使用测试弹簧轮廓进行单元测试.我正在尝试使用spring.cloud.config.enabled:false和禁用EnableDiscoveryClient测试配置文件的注释,但它不起作用.
我正在使用spring.cloud.consul 1.0.0.BUILD-SNAPSHOT.这是一个例外:
com.ecwid.consul.transport.TransportException:java.net.ConnectException:连接被拒绝:通过com.ecwid.consul.transport.DefaultHttpTransport连接com.ecwid.consul.transport.DefaultHttpTransport.executeRequest(DefaultHttpTransport.java:87). makeGetRequest(DefaultHttpTransport.java:46)at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:66)
我想使用Spring RestTemplate进行简单的HTTP POST.Wesb服务接受参数中的JSON,例如:{"name":"mame","email":"email@gmail.com"}
public static void main(String[] args) {
final String uri = "url";
RestTemplate restTemplate = new RestTemplate();
// Add the Jackson message converter
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
// create request body
String input = "{ \"name\": \"name\", \"email\": \"email@gmail.com\" }";
JsonObject request = new JsonObject();
request.addProperty("model", input);
// set headers
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", "Basic " + "xxxxxxxxxxxx");
HttpEntity<String> entity = new HttpEntity<String>(request.toString(), headers);
// send request and parse result
ResponseEntity<String> response = restTemplate
.exchange(uri, HttpMethod.POST, …Run Code Online (Sandbox Code Playgroud) Intellij 无法识别 @SLF4J 注释。我有以下错误:
Error:(105, 9) java: cannot find symbol
symbol: variable log
location: class com.xxxxx.SdsConfig
Run Code Online (Sandbox Code Playgroud)
知道我已经启用注释处理(设置 -> 编译器 -> 注释处理器)
我使用 java 8 编译器。
我是Zuul作为边缘服务器.所有请求都通过此边缘服务器传递.我有一个微服务A.A的所有Web服务都受基本身份验证保护.我们如何通过Zuul代理调用A b的服务?我应该为邮件添加标题吗?
java ×4
spring-cloud ×3
consul ×2
netflix-zuul ×2
spring ×2
certificate ×1
intellij-14 ×1
lombok ×1
rest ×1
security ×1
spring-boot ×1
spring-mvc ×1
spring-rest ×1
ssl ×1
web-services ×1