grails-core
grails-core copied to clipboard
Grails app should auto import spring component
Expected Behavior
It should see demo
When add @ComponentScan
to Application
, it run success.
Grails support grails.spring.bean.packages
, but I think this config for external packages, Grails App should auto scan package where Application
belong.
import org.springframework.context.annotation.ComponentScan
@CompileStatic
@ComponentScan
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
Actual Behaviour
Class: java.lang.NullPointerException
Message: null
Caused by: Cannot get property 'name' on null object
Steps To Reproduce
grails create-app com.rainboyan.demo.app-component-auto-scan-issue
grails run-app
open http://localhost:8080/demo/index
When render demo
, it's OK!
Environment Information
Grails Version: 5.1.2 JVM Version: 11.0.14 OS: MacOS 11.6.4 M1
Example Application
https://github.com/rainboyan/grails-app-component-auto-scan-issue
Version
5.1.2
No it should not. I don't want increased startup time. Use Componentscan if you want this functionality.
@olavgg FYI... There is a relevant discussion thread in the PR at https://github.com/grails-profiles/base/pull/97.
Thank you for your feedback.
I'll close this issue for now. Based on my tests, using @ComponentScan
will not cause performance problems, but in some scenarios it may not work, which is caused by Grails' plugin mechanism.
Spring Boot provides many solutions for performance optimization, such as Lazy Initialization in Spring Boot 2.2, Generating an Index of Candidate Components, run pre initialization in a background thread of time consuming tasks, use functional bean definitions instead of @Configuration
, reduce unnecessary class and library loading, keep bootstrap configurations and plugins clean and minimalized.
Although Grails is built on top of Spring Boot, it does not take full advantage of its advantages. Grails 5 has a lot of room for optimization and improvement, but unfortunately, the team is not currently investing in this area.
Thanks to everyone on the team for their hard work and contributions, I will continue to pay attention to Grails performance issues and report back to the community.