eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
690 stars 351 forks source link

Spring Example Throws NoSuchMethodException For 'value' on Autowired Annotation #2588

Open jerseyrobot opened 10 years ago

jerseyrobot commented 10 years ago

Create a file called 'jul.properties' in the 'jersey/examples/helloworld-spring-webapp' directory with the following contents:

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.SimpleFormatter.format=%4$-7s [%3$s] %5$s%6$s%n

.level=ALL
org.glassfish.jersey.level=ALL
org.glassfish.jersey.tracing.level=FINEST

Run this command:

mvn -Djava.util.logging.config.file=jul.properties jetty:run

In the logging output observe lines like this:

Jan 6, 2014 10:29:11 PM org.glassfish.jersey.server.model.Parameter getValue
FINER: Unable to get the com.sun.proxy.$Proxy35 annotation value property
java.lang.NoSuchMethodException: org.springframework.beans.factory.annotation.Autowired.value()
    at java.lang.Class.getMethod(Class.java:1641)
    at org.glassfish.jersey.server.model.Parameter.getValue(Parameter.java:458)
        ...

Expected behaviour: example apps shouldn't throw spurious errors.

(Impact of this bug: I have had a long struggle to upgrade a Jersey 1.8 application to Jersey 2.5 and when I encountered this exception I spent quite a while trying to understand and 'fix' it, before I realized that it was expected.)

Environment

OS X 10.9.1, Java 7

Affected Versions

[2.5.1]

jerseyrobot commented 6 years ago
jerseyrobot commented 10 years ago

@glassfishrobot Commented Reported by ilesm

jerseyrobot commented 10 years ago

@glassfishrobot Commented @mpotociar said: Can you please provide the complete stacktrace for the exception so that we can get a better picture about the reason why the exceptional situation occured?

Also, note that the application is not throwing the exception - it is only logging the exception that is not propagated further. It is IMO a good practice to log exceptions when consuming them without processing. Maybe we could just log this as FINEST level?

jerseyrobot commented 10 years ago

@glassfishrobot Commented ilesm said:

INFO: Initiating Jersey application, version Jersey: 2.5.1-SNAPSHOT 2013-12-20 21:00:47...
Jan 15, 2014 9:16:05 AM org.glassfish.jersey.internal.ServiceFinder$LazyObjectIterator next
FINEST: Loading next object: org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl
Jan 15, 2014 9:16:05 AM org.glassfish.jersey.server.model.Parameter getValue
FINER: Unable to get the com.sun.proxy.$Proxy35 annotation value property
java.lang.NoSuchMethodException: org.springframework.beans.factory.annotation.Autowired.value()
    at java.lang.Class.getMethod(Class.java:1641)
    at org.glassfish.jersey.server.model.Parameter.getValue(Parameter.java:458)
    at org.glassfish.jersey.server.model.Parameter.create(Parameter.java:320)
    at org.glassfish.jersey.server.model.IntrospectionModeller.checkResourceClassFields(IntrospectionModeller.java:212)
    at org.glassfish.jersey.server.model.IntrospectionModeller.doCreateResourceBuilder(IntrospectionModeller.java:137)
    at org.glassfish.jersey.server.model.IntrospectionModeller.access$000(IntrospectionModeller.java:80)
    at org.glassfish.jersey.server.model.IntrospectionModeller$1.call(IntrospectionModeller.java:111)
    at org.glassfish.jersey.server.model.IntrospectionModeller$1.call(IntrospectionModeller.java:108)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
    at org.glassfish.jersey.server.model.IntrospectionModeller.createResourceBuilder(IntrospectionModeller.java:108)
    at org.glassfish.jersey.server.model.Resource.from(Resource.java:744)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:379)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:162)
    at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:304)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:301)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:169)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:359)
    at javax.servlet.GenericServlet.init(GenericServlet.java:241)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
    at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Jan 15, 2014 9:16:05 AM org.glassfish.hk2.utilities.reflection.Logger debug
jerseyrobot commented 10 years ago

@glassfishrobot Commented @shamoh said: I guess we should not log any error whenever there is not value method on annotation instance.

package org.glassfish.jersey.server.model;
...
public class Parameter implements AnnotatedElement {
...

    private static String getValue(Annotation a) {
        try {
            Method m = a.annotationType().getMethod("value");
            if (m.getReturnType() != String.class) {
return null;
            }
            return (String) m.invoke(a);
        } catch (Exception ex) {
            if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER,
        String.format("Unable to get the %s annotation value property", a.getClass().getName()), ex);
            }
        }
        return null;
    }
jerseyrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JERSEY-2316