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 Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

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

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

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

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

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

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

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

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

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

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

Fernandez Ludovic commented

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

@spring-projects-issues
Copy link
Collaborator Author

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

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

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 A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) 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 Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants