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

Stop @EnableWebMvc from being automatically added to Grails Applications #13863

Draft
wants to merge 1 commit into
base: 7.0.x
Choose a base branch
from

Conversation

codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Nov 20, 2024

This produces unknown/unexpected behavior and should not be done. @EnableWebMvc is a Spring Framework configuration annotation not to be used with Spring Boot. It produces undesired behavior by automatically creating beans that are not wanted. WebMvcAutoConfiguration performs all the behavior of this configuration because it extends it and adds conditional logic.

Fixes

Overriding bean definition for bean 'localeResolver' with a different definition: replacing [Root bean: class=null; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; fallback=false; factoryBeanName=org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; factoryMethodName=localeResolver; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration] with [Generic bean: class=org.springframework.web.servlet.i18n.SessionLocaleResolver; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; fallback=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null]
Overriding bean definition for bean 'org.springframework.aop.config.internalAutoProxyCreator' with a different definition: replacing [Root bean: class=org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; fallback=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null] with [Generic bean: class=org.grails.spring.aop.autoproxy.GroovyAwareInfrastructureAdvisorAutoProxyCreator; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; fallback=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null]
class WebMvcAutoConfiguration {
    static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration { 
    } 
}

class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
}

class WebMvcConfigurationSupport extends WebMvcConfigurationSupport {
    @Bean public LocaleResolver localeResolver() { }
}

vs

@Import(DelegatingWebMvcConfiguration.class)
public @interface EnableWebMvc { }

This pull request is not finished

@codeconsole
Copy link
Contributor Author

#13843

@matrei
Copy link
Contributor

matrei commented Nov 20, 2024

Did you try this out with grails-functional-tests?
I get the following errors:

BookFunctionalSpec > Test that when the /viewBooks URL is hit it redirects to the book list FAILED
    Condition not satisfied:

    title == "Book List"
    |     |
    |     false
    |     36 differences (7% similarity)
    |     (HTTP) (Statu)s( 500 – In)t(ernal Server Error)
    |     (Book) (Li---)s(---------)t(------------------)
    HTTP Status 500 – Internal Server Error
        at functionaltests.BookFunctionalSpec.Test that when the /viewBooks URL is hit it redirects to the book list(BookFunctionalSpec.groovy:15)
'2024-11-20 17:31:50.853 ERROR --- [nio-8080-exec-1] .C.[.[.[.[dispatcherServletRegistration] : Servlet.service() for servlet [dispatcherServletRegistration] in context with path [] threw exception

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.sitemesh.webapp.contentfilter.HttpServletRequestFilterable@6b88ebe0' with class 'org.springframework.web.context.request.ServletRequestAttributes' to class 'org.grails.web.servlet.mvc.GrailsWebRequest'
	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:415)

@codeconsole
Copy link
Contributor Author

Did you try this out with grails-functional-tests? I get the following errors:

@matrei please read above "This pull request is not finished"

@matrei
Copy link
Contributor

matrei commented Nov 20, 2024

Sorry, I thought I got a review request.

@codeconsole
Copy link
Contributor Author

Sorry, I thought I got a review request.

@matrei well, technically you did, but I immediately cancelled it and added the line "this pull request is not finished" before you got here😜

@jeffscottbrown
Copy link
Member

This pull request is not finished

I have converted this PR to Draft for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants