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

context:component-scan element says error in the mvc-cofig.xml [SPR-11221] #15846

Closed
spring-projects-issues opened this issue Dec 12, 2013 · 14 comments
Assignees
Labels
in: core status: backported type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Dec 12, 2013

not-three opened SPR-11221 and commented

When I migrate 3.2.5.Release to 4.0.0.Realse, the following config tells errors

<context:component-scan base-package="it.web,com.sowell">
</context:component-scan>

The error message is, "Error occured processing XML '[Ljava.lang.String; cannot be cast to java.lang.String'. See Error Log for more details"

!https://jira.springsource.org/secure/attachment/21541/component-scan.jpg!


Affects: 4.0 GA

Attachments:

Referenced from: commits 7ad6df8, 2a3ca61, 23546b1

Backported to: 3.2.7

0 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 16, 2013

Juergen Hoeller commented

What's the stacktrace there? This exception doesn't seem to come from Spring's own parsing code...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 16, 2013

not-three commented

<context:component-scan
     base-package="com.sowell.modules,com.sowell.test,iweb.security.captcha.web"
     use-default-filters="false">
     <context:include-filter type="annotation"
          expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>

This is the recent configuration, and the error message prints:

java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:92)
at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:70)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:247)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 17, 2013

Juergen Hoeller commented

Ok, so it looks like a mismatch between ControllerAdvice's new "value" attribute of type String[]... whereas @Component conventions suggest that if "value" exists, then it is expected to be a component name of type String.

We'll fix this for 4.0.1.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 17, 2013

Juergen Hoeller commented

Strangely enough, the Spring 4.0 version of the AnnotationBeanNameGenerator class does check whether the "value" attribute is a String in isStereotypeWithNameValue already... So as far as I can see, it wouldn't ever enter the code block where it casts the value to a String, since isStereotypeWithNameValue would have returned false before...

Anyway, I'll modify that code to proceed more defensively, checking the String value type right before the case. I'm not sure how your current ClassCastException manages to happen, but after such a restructuring of the code, there is no chance in can ever happen - not even with an overridden isStereotypeWithNameValue method or the like.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 17, 2013

Juergen Hoeller commented

Hopefully addressed through the above-mentioned code rearrangement. Please test a 4.0.1 snapshot accordingly; see http://projects.spring.io/spring-framework/ for repo information.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 17, 2013

not-three commented

Just display errors, the application base spring 4 still run properly so far.
Thanks very much

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 17, 2013

not-three commented

			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.0.1.BUILD-SNAPSHOT</version>

I have test this version, errors message still remained.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 17, 2013

not-three commented

I copy ControllerAdvice and AnnotationBeanNameGenerator source file from the github, re-compile spring-context and spring-web, and replace org.springframework.context_4.0.0.20130829-M3.jar and org.springframework.web_4.0.0.20130829-M3.jar in the eclipse pulgins directory. Now it's has no errors, so the Spring Tool Suite and it's plugin need updated too. Thanks again.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 9, 2014

John Andrew Barnes commented

If it's any help, I can reproduce this bug by adding "@ControllerAdvice" to one of the controllers scanned by <context:component-scan... When I comment it out, the error disappears.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 7, 2014

Ricardo Rodriguez Garcia commented

I am testing with release version 4.0.1 the erros is still showning but if the marker is removed from eclipse the application runs fine. However the error will return if a clean is performed on the project and then rebuild.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 9, 2014

Fernandez Ludovic commented

Please re-open this issue, problem is not resolved with 4.0.1.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 10, 2014

Juergen Hoeller commented

Is the only remaining problem that Spring Tool Suite doesn't include Spring Framework 4.0.1 yet? In that case, it should rather be reported to the STS team...

From the Spring Framework perspective, it's not clear what we could do to further improve the situation. If there is anything specific, let us know.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 17, 2015

Tarundeep Singh commented

I am still facing this issue. Seems most likely to be same issue.

Posted details here:
http://stackoverflow.com/questions/30898507/spring-4-controlleradvice-jsonp-support-for-responsebody-causes-deployment-e

Request you to review this issue once again.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 19, 2015

Baptiste Gaillard commented

Hi, we also encounter this problem, I'm using Spring 4.2.2.RELEASE and I updated all my Eclipse plugins today (i'm using last version of Eclipse Mars).

As the cause of this problems seems to be the @ControllerAdvice annotation is it possible to configure a controller advice using XML configuration instead ?

@spring-projects-issues spring-projects-issues added type: bug status: backported in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.0.1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: backported type: bug
Projects
None yet
Development

No branches or pull requests

2 participants