spring cloud Eureka server 问题 Spring Cloud java.lang.TypeNotPresentException

版本:

spring-cloud.version : Greenwich.SR2 

 

pom配置:

 

 1  2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     4.0.0
 5     
 6         org.springframework.boot
 7         spring-boot-starter-parent
 8         2.1.7.RELEASE
 9     
10     com.test
11     3-spring-eureka-server
12     0.0.1-SNAPSHOT
13 
14     
15         1.8
16         Greenwich.SR2
17     
18 
19     
20         
21             org.springframework.cloud
22             spring-cloud-starter-netflix-eureka-server
23         
24         
25             org.springframework.cloud
26             spring-cloud-starter-config
27         
28         
29             org.springframework.boot
30             spring-boot-starter-test
31             test
32          
33 
34     
35 
36     
37         
38             
39                 org.springframework.cloud
40                 spring-cloud-dependencies
41                 ${spring-cloud.version}
42                 pom
43                 import
44             
45         
46     
47 
48     
49         
50             
51                 org.springframework.boot
52                 spring-boot-maven-plugin
53             
54         
55     
56 
View Code

 

application.properties:

spring.application.name=spring-cloud-eureka-server

server.port=8761
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
View Code

 

启动AppServer:

package com.springtest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class AppServer {
    public static void main(String[] args) {
        SpringApplication.run(AppServer.class, args);
    }
}
View Code

 

出现错误信息:

Spring Cloud java.lang.TypeNotPresentException

 

 

解决方案如下:

 

是因为用了jdk12的缘故。因为JAXB-API是java ee的一部分,在jdk12中没有在默认的类路径中。从jdk9开始java引入了模块的概念,可以使用模块命令--add-modles java.xml.bind引入jaxb-api。也可以选择另一种解决方法,在maven里面加入下面依赖,可以解决这个问题:

 

pom中添加依赖:


    javax.xml.bind
    jaxb-api
    2.3.0


    com.sun.xml.bind
    jaxb-impl
    2.3.0


    org.glassfish.jaxb
    jaxb-runtime
    2.3.0


    javax.activation
    activation
    1.1.1
View Code

 

最终的Pom.xml 文件如下:


    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
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.7.RELEASE
    
    com.test
    3-spring-eureka-server
    0.0.1-SNAPSHOT

    
        1.8
        Greenwich.SR2
    

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
        
            org.springframework.cloud
            spring-cloud-starter-config
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            javax.xml.bind
            jaxb-api
            2.3.0
        
        
            com.sun.xml.bind
            jaxb-impl
            2.3.0
        
        
            org.glassfish.jaxb
            jaxb-runtime
            2.3.0
        
        
            javax.activation
            activation
            1.1.1
        

    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

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

 

转载于:https://www.cnblogs.com/tianciliangen/p/11441935.html

你可能感兴趣的:(spring cloud Eureka server 问题 Spring Cloud java.lang.TypeNotPresentException)