Open fredgalvao opened 6 years ago
Upload an example project that reproduces the issue. I don't think the two issues you linked to are related to anything with the servlet class
The stacktrace on #125 is exactly the same, that made me think they were related. I supposed the grails version support could relate because this seems like the execution context for the scripts on this plugin doesn't match 100% of what's needed from grails (similar to what unit tests do).
@jameskleeh Updated the main post with the Example Application
section. Minimal changes to the pure grails shell, and results are exactly the same.
Heads Up: there's a chance this is actually a grails issue, as it is reproducible with
grails console
too. I wanted to make sure here first, as it's the main scenario I have.Consider:
dbm-gorm-diff
): DMSTask List
Steps to Reproduce
webapp
Expected Behaviour && Actual Behaviour
Issue The servletContext obtainable through multiple sources/means, during the bean configuration phase, for both MA and PLUGIN, in the context of a DMS, is a
org.springframework.mock.web.MockServletContext
, even though GDM+MA fires up the "grails application" context in thedevelopment
profile (spring security is loaded, bootstrap runs, beans register, etc). It should beorg.apache.catalina.core.ApplicationContextFacade
, or any other implementation of aServletContext
that is properly setup, so thatgetRealPath
(for example) would work.My issue I have an application with GDM, and another internal plugin that sets up a bean (easy stuff). On the configuration of this bean, I need to access the real path of something inside
src/main/webapp
(standard stuff). Forrun-app
ortest-app
and it's derivatives, it shines: I can access servletContext any way I want [holders, mainContext, bean], and it's a valid instance, andgetRealPath
returns stuff from where it is, dev or prod. Then, when I need to rundbm-gorm-diff changelog-bacon.groovy
, it fails with a few NPE, caused by the fact that servletContext isn't accessible through all means, and is a mock otherwise. I've tried many other ways to get the real path to a file there but with no success (this isn't really an issue with the plugin, just colateral damage).Environment Information
1.8.0_152
: OpenJDK 64-Bit Server VM (Zulu 8.25.0.1-linux64) (build 25.152-b16, mixed mode)Example Application
Changes made to the pure
grails create-app
worth mentioning:@ComponentScan
to ApplicationStacktraces and code snippets
ON DMS
WARN MockServletContext : Couldn't determine real path of resource class path resource [src/main/webapp] java.io.FileNotFoundException: class path resource [src/main/webapp] cannot be resolved to URL because it does not exist <LONG STACKTRACE I DON'T THINK IS USEFUL FOR NOW> MABeansConfiguration : @Autowired servletContext.getRealPath('.')::null
WARN MockServletContext : Couldn't determine real path of resource class path resource [src/main/webapp/] java.io.FileNotFoundException: class path resource [src/main/webapp/] cannot be resolved to URL because it does not exist <LONG STACKTRACE I DON'T THINK IS USEFUL FOR NOW> MABeansConfiguration : @Autowired servletContext.getRealPath('/')::null
MABeansConfiguration : @Autowired servletContext::org.apache.catalina.core.ApplicationContextFacade@652e64bb MABeansConfiguration : Holders.servletContext::org.apache.catalina.core.ApplicationContextFacade@652e64bb MABeansConfiguration : ServletContextHolder.servletContext::org.apache.catalina.core.ApplicationContextFacade@652e64bb MABeansConfiguration : @Autowired grailsApplication.mainContext::org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11a95360: startup date [Wed Apr 25 20:52:10 BRT 2018]; root of context hierarchy MABeansConfiguration : @Autowired grailsApplication.mainContext?.servletContext::org.apache.catalina.core.ApplicationContextFacade@652e64bb MABeansConfiguration : this.getClass().getResource("/").getPath()::/build/classes/integrationTest/
MABeansConfiguration : getProtectionDomain().getCodeSource()::/build/classes/main/
MABeansConfiguration : this.getClass().getClassLoader().getResource('.')::file:/build/classes/integrationTest/
MABeansConfiguration : this.getClass().getClassLoader().getResource('/')::null
MABeansConfiguration : @Autowired servletContext.getRealPath('.')::/src/main/webapp
MABeansConfiguration : @Autowired servletContext.getRealPath('/')::/src/main/webapp/