概述
在一个子模块中,引入Eureka-Server的包,启动就报错
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
解决
这是由于没有在父工程锁定SpringCloud版本导致的,锁定一下即可
Eureka-Server的jar包
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
Eureka-Client的jar包
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
父工程锁定版本
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Eureka的访问地址是
http://localhost:6868/
http://localhost:port 即 http://localhost:端口号
server的配置文件
eureka:
client:
service-url:
defaultZone: http://localhost:${server.port}/eureka/
fetch-registry: false
register-with-eureka: false
client的配置文件
eureka:
client:
service-url:
defaultZone: http://localhost:6868/eureka/
启动类
@SpringBootApplication
@MapperScan("com.tensquare.qa.dao")
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public class QaApplication {
public static void main(String[] args) {
SpringApplication.run(QaApplication.class);
}
@Bean
public JwtUtil jwtUtil(){
return new JwtUtil();
}
}
@SpringBootApplication
@MapperScan("com.tensquare.user.dao")
@EnableEurekaClient
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class);
}
@Bean
public JwtUtil jwtUtil(){
return new JwtUtil();
}
}
Client
//用feign不调用不能用下划线
@FeignClient("tensquare-base")
public interface BaseClient {
//路径,@PathVariable必须要写
@RequestMapping(value = "/label/{labelId}",method = RequestMethod.GET)
public Result findById(@PathVariable("labelId")String labelId);
}
Controller
qa
@RequestMapping(value = "/tb-user/testFeign",method = RequestMethod.GET)
public Result testFeign(@RequestParam("id") String id){
Result result = feignTest.getUserById(id);
return result;
}
user
@RequestMapping(value = "/testFeign",method = RequestMethod.GET)
public Result getUserById(@RequestParam("id") String id){
TbUser tbUser = iTbUserService.getById(id);
return new Result(StatusCode.OK,"查询成功",tbUser);
}
微服务之间有时候会抛出异常,多等等。