在Spring靴2.3.3上试用网飞·海斯特里克斯时,出现以下错误...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'freeMarkerConfigurer' defined in org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration: Invocation of init method failed; nested exception is java.lang.NoSuchFieldError: DEFAULT_INCOMPATIBLE_IMPROVEMENTS
主要SimpleClientApplication.java有以下注释
@SpringBootApplication
@EnableCircuitBreaker
@EnableHystrixDashboard
ProductListController。Java语言
@RestController
@EnableAutoConfiguration(exclude = { FreeMarkerAutoConfiguration.class })
public class ProductListController {
@GetMapping
@HystrixCommand(fallbackMethod = "defaultProducts")
public List<String> cloudProductList() {
RestTemplate restTemplate = new RestTemplate();
URI uri = URI.create("http://localhost:8090/products");
return restTemplate.getForObject(uri, List.class);
}
public List<String> defaultProducts() {
return Arrays.asList("Spring Cloud");
}
}
啪啪.xml...
4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.3.RELEASE com.demo simple-client-application 1.0 simple-client-application Spring Boot 的演示项目
<properties>
<java.version>14</java.version>
<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.9</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
</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>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我尝试了许多解决方案:
这些组合都不适合我,在我的Spring-Boot应用程序的每次启动时,我都会遇到您提到的相同错误。
最后我发现只要重新定义后缀:
spring
freemarker:
suffix: .ftl
并设置:
@EnableAutoConfiguration(exclude = {FreeMarkerAutoConfiguration.class})
在我的AppConfig
类(包含@Configuration
注释的类)中,我的应用程序在更改后启动。
我必须提到,我使用Freemarker时没有存储在我的应用html" target="_blank">程序中的模板,而只是将其用作运行时依赖项(我的Freemarker模板只是在我的类方法中传递的文本(Java字符串),然后我并不真正关心文件扩展名。我不想使用 Freemarker 自动配置,我只是明确添加了依赖项:
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>