使用官网生成的eureka注册服务项目启动时无法渲染freemaker模板而是返回xml响应。
1. parent pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" 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"> <modelVersion>4.0.0</modelVersion> <groupId>com.ycx.cloud</groupId> <artifactId>cloud</artifactId> <version>1.0</version> <packaging>pom</packaging> <!-- {@see} http://projects.spring.io/spring-cloud/ --> <!-- lookup parent from repository(super POM) --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> </parent> <modules> <module>cloud-server-center</module> </modules> <properties> <maven.compile.source>1.8</maven.compile.source> <maven.compile.target>1.8</maven.compile.target> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-cloud.version>Edgware.SR1</spring-cloud.version> <druid.version>1.1.6</druid.version> <fastjson.version>1.2.36</fastjson.version> <lombok.version>1.16.14</lombok.version> <!-- plugins version --> <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> <maven-source-plugin.version>2.4</maven-source-plugin.version> <maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version> </properties> <!-- dependencies --> <dependencies> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> </dependency> </dependencies> </dependencyManagement> <!-- repository --> <repositories> <repository> <id>oss</id> <name>oss</name> <url>https://oss.sonatype.org/content/groups/public</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/libs-milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> <configuration> <source>${maven.compile.source}</source> <target>${maven.compile.target}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>${maven-source-plugin.version}</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>${maven-deploy-plugin.version}</version> </plugin> </plugins> </pluginManagement> </build> </project>
2. eureka pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" 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"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>eureka-center</artifactId> <groupId>com.ycx.cloud</groupId> <version>1.0</version> </parent> <artifactId>cloud-eureka-center</artifactId> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <!-- Spring Cloud Starter Eureka Server (deprecated, please use spring-cloud-starter-netflix-eureka-server) --> <!-- <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> --> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <!-- build --> <build> <finalName>eureka-center</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
3. application.yml
spring: application: name: cloud-server-center freemarker: prefer-file-system-access: false thymeleaf: enabled: false server: port: 8088 eureka: instance: hostname: localhost instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}} client: registerWithEureka: false #false: dont't register to server center as a client fetchRegistry: false #true throws Cannot execute request on any known server waitTimeInMsWhenSyncEmpty: 0 #serviceUrl: # defaultZone: http://localhost:${server.port}/eureka #dashboard: # path: / # Full authentication is required to access actuator endpoints. # Consider adding Spring Security or set 'management.security.enabled' to false. management: security: enabled: false
4.运行
使用 mvn spring-boot:run 运行工程,在centos6,windows10,jdk8环境下测试,UI均不正常显示,根据stackoverflow和官方源代码的issue均不能解决。排除eureka项目的依赖时发现,freemarker-2.3.x-incubating依赖,根据maven中心仓库查询情况。这个孵化版本应该存在问题。freemarker版本调整如下:
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
重新编译后启动项目,问题解决。
附注:
- 自定义dashboard显示界面,可以将spring-cloud-netflix-eureka-server-1.x.x.RELEASE.jar中static和templates文件夹拷贝至当前maven工程中的src/main/resources目录下进行自定义修改。
- 服务中心运行一段时间提示
EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
据查和自注册服务相关。 - system status下信息环境显示test
Environment test Data center default
附:https://stackoverflow.com/questions/43314822/spring-eureka-dashboard-returns-xml-on-wildfly