Spring / ZUUL – Failed to introspect annotated methods

The Problem

Working through the spring security tutorial at https://spring.io/guides/tutorials/spring-security-and-angular-js/ and I’ve found a few issues with the instructions (more on those later perhaps).

The bit that really caused me some issues though was when introducing the API Gateway concept. Following the instructions I added the @EnableZuulProxy to the UIApplication java file:

@SpringBootApplication
@RestController
@EnableZuulProxy
public class UIApplication {
    ...

Along with the import statement (not mentioned in the tutorial):

import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

And the dependencies in the pom.xml file (as specified in the tutorial):

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Camden.SR2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zuul</artifactId>
    </dependency>
    ...
<dependencies>

Now, when building the project I get the following:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.ServletRegistrationBean
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 ... 31 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.493 s
[INFO] Finished at: 2017-10-07T09:58:15+01:00
[INFO] Final Memory: 81M/386M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) on project ui: An exception occurred while running. null: InvocationTargetException: Failed to process import candidates for configuration class [com.test.ui.UIApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.zuul.ZuulConfiguration: org/springframework/boot/context/embedded/ServletRegistrationBean: org.springframework.boot.context.embedded.ServletRegistrationBean -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

The Solution

I really struggled to find anything about the error around the internets and the solution was so simple…

Within the pom.xml (from the github version of the tutorial pom), the version should be:

<version>Dalston.SR2</version>

rather than:

<version>Camden.SR2</version>

That’s it. So simple.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s