最近研究Spring Cloud,结果发现在设置eureka server时一直报错。
项目是直接利用Spring Initializr导出的maven项目。使用的是JDK 12,Spring Cloud的版本是Greenwich.SR1。
通过研究报错的信息发现问题出在
java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present
通过搜索发现原来是JAXB-API未被加载到JDK中,从9.0以后的版本估计都有这个问题。
解决的方法也很简单,直接在pom.xml文件里面添加相关的依赖即可。
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>RELEASE</version>
</dependency>