1

While trying out Netflix hystrix on Spring boot 2.3.3 gives the following error - ...

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

Main SimpleClientApplication.java has following annotation

@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");
    }
}

pom.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 Demo project for 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>
  • Does this answer your question? [Is there a compatibility matrix of Spring-boot and Spring-cloud?](https://stackoverflow.com/questions/42659920/is-there-a-compatibility-matrix-of-spring-boot-and-spring-cloud) – sorifiend Sep 04 '20 at 02:31
  • It looks like you are using an incompatible version of spring cloud for the spring boot version. Your dependencies show cloud `2.1.0`, but from what you likely need `2.2.0` or newer to be compatible with spring boot `2.3.3`. Specifically, you need the Hoxton releases https://spring.io/blog/2019/11/28/spring-cloud-hoxton-released – sorifiend Sep 04 '20 at 02:35

1 Answers1

0

I tried many solutions:

  • Adjusted maven pom with freemarker exclusions and adding explicitly spring-context-support.
  • Added spring.freemarker.check-template-location: false
  • Added spring.freemarker.enabled: false

and none of these combinations were working for me, at every start of my Spring-Boot App I got the same error you mentioned.

Finally I found that just re-defining the suffix with:

spring
  freemarker:
    suffix: .ftl

and setting up:

@EnableAutoConfiguration(exclude = {FreeMarkerAutoConfiguration.class})

in my AppConfig class (the Class which contains the @Configuration annotation), my App is starting after that change.

I have to mention that I use Freemarker without template stored in my App but just using it as a runtime dependency (my Freemarker templates are just texts (Java String) passed in my Class Methods), then I don't really care about the file extensions. I do not want to use the Freemarker auto-configure and I just added the dependency explicitly:

<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>${freemarker.version}</version>
</dependency>
рüффп
  • 5,172
  • 34
  • 67
  • 113