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

BootStrap init closure servletContext cleanup #13999

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package functionaltests

import functionaltests.*
import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
Book.withTransaction {
new Book(title:"Example Book").save(flush:true)
assert Book.count() == 1
}
}

def destroy = {
}
}
7 changes: 6 additions & 1 deletion grails-test-examples/app2/grails-app/init/BootStrap.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package app3

import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package demo

import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package gorm

import gorm.*
import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
Book.withTransaction {
def b = new Book(title:"The Stand")

Expand All @@ -20,8 +22,8 @@ class BootStrap {
paris.addToUsers(name:"Joe")
paris.save(flush:true)
}

}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package issue11102

import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package issueviews182

import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package micronaut

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package issue11005

import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package loadafter

import jakarta.servlet.ServletContext

class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class BootStrap {

def init = { servletContext ->
ServletContext servletContext

def init = {
}

def destroy = {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface GrailsBootstrapClass extends GrailsClass {
/**
* Calls the init closure if one exists.
*/
void callInit(ServletContext servletContext);
void callInit();

/**
* Calls the destroy closure if one exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public Object getReferenceInstance() {
}

public Closure<?> getInitClosure() {

Object obj = ClassPropertyFetcher.getInstancePropertyValue(instance, INIT_CLOSURE);
if (obj instanceof Closure) {
return (Closure<?>)obj;
Expand All @@ -64,13 +63,9 @@ public Closure<?> getDestroyClosure() {
return BLANK_CLOSURE;
}

public void callInit(ServletContext servletContext) {
public void callInit() {
Closure<?> init = getInitClosure();
if (init != null) {
Class[] parameterTypes = init.getParameterTypes();
if(parameterTypes != null) {
init = init.curry(new Object[]{servletContext});
}
Environment.executeForCurrentEnvironment(init);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void executeGrailsBootstraps(GrailsApplication application, WebApp
final Object instance = bootstrapClass.getReferenceInstance();
webContext.getAutowireCapableBeanFactory().autowireBeanProperties(
instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
bootstrapClass.callInit(servletContext);
bootstrapClass.callInit();
}
if (interceptor != null) {
interceptor.flush();
Expand Down
Loading