Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<mvc:annotation-driven>'s checks for JSR-303 and JAXB2 fail in an OSGi environment [SPR-7291] #11950

Closed
spring-projects-issues opened this issue Jun 16, 2010 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Dmitry Sklyut opened SPR-7291 and commented

AnnotationDrivenBeanDefinitionParser uses static fields to store result of presence check for jackson, rome, jsr303 and jaxb.

Consider changing that approach to either use non-static fields or running the check when needed. Behavior of statics will be unpredictable in OSGi environment. Also consider using classloader of bean factory vs. classloader that loaded the AnnotationDrivenBeanDefinitionParser.


Affects: 3.0.2

Referenced from: commits 89fadb9

@spring-projects-issues
Copy link
Collaborator Author

Dmitry Sklyut commented

It looks like this issue will be in any class that does something like this:

For example:

private static final boolean jodaTimePresent = ClassUtils.isPresent(
          "org.joda.time.DateTime", FormattingConversionService.class.getClassLoader());

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

In what sense is this unpredictable in an OSGi environment? I would still expect those classes to be properly linked at the time of static field initialization, resolving the optional third-party dependencies if they are present. We need to use the corresponding Spring module's ClassLoader here since this is what we load our support classes with - the classes which actually depend on those third-party libraries - referenced directly in AnnotationDrivenBeanDefinitionParser itself.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Dmitry Sklyut commented

Pardon my comment about statics. Was made in haste.

I did a bit more digging and here is what I see:

Class loader of AnnotationDrivenBeanDefinitionParser
KernelBundleClassLoader: [bundle=org.springframework.web.servlet_3.0.2.RELEASE]

ClassUtils.isPresent(type, classLoader) raises this exception:
Exception: ex = {com.springsource.kernel.osgi.framework.ExtendedClassNotFoundException@9099}"com.springsource.kernel.osgi.framework.ExtendedClassNotFoundException: javax.validation.Validator in KernelBundleClassLoader: [bundle=org.springframework.web.servlet_3.0.2.RELEASE]"

org.springframework.web.servlet does not import joda, javax.validation or javax.xml.bind. It does import rome and jackson.
I confirmed that jackson is resolved to "true" as I have those bundles deployed.

TCCL at the time of isPresent call is:
getDefaultClassLoader() = {com.springsource.osgi.webcontainer.tomcat.internal.loading.BundleWebappClassLoader@9066}

I have not drilled down into TCCL but I would assume that it "knows" about joda, jsr303 etc as all those packages are imported in my web-app bundle and I don't see CNF during runtime.

I guess switching to ClassUtils.isPresent(className) solves this.
Not sure if optionally importing dependencies of supporting classes in web.servlet bundle would be a better choice. It could be as manifest provides an accounting of third party dependencies that can potentially be used by web.servlet.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

As of Spring 3.0.4, we have optional imports for all of those libraries in the web-servlet module manifest now.

This will be available in tomorrow's 3.0.4 snapshot. Feel free to give it an early try...

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants