micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.07k stars 1.07k forks source link

Ability to access ApplicationContextBuilder from Groovy Function #867

Open musketyr opened 5 years ago

musketyr commented 5 years ago

Steps to Reproduce

  1. Create a library with GORM entity in package com.example.foo
  2. Create Groovy function in package com.example.fn using the GORM entity from com.example.foo
  3. Deploy function to AWS

Expected Behaviour

Unless configured, the function will fail. But there should be way how to call ApplicationContextBuilder.packages('com.example.foo') from the function script which at the moment does not trigger AbstractExecutor.buildApplicationContext(context) at all which is otherwise dedicated to this purpose like following

    @Override
    protected ApplicationContext buildApplicationContext(@Nullable Object context) {
        return ApplicationContext.build(Environment.FUNCTION).packages('com.example.foo').build();
    }

One of the solutions would be to let the Groovy script take an advantage of AbstractExecutor.buildApplicationContext(context) or create a generic annotation which would be able to add additional packages for scanning and which can be applied on the package declaration of the Groovy script e.g.

@ScanPackages('com.example.foo')
package com.example.fn

Actual Behaviour

There is no way how to set packages for scanning for Groovy function.

Environment Information

ed-luke commented 4 years ago

I see this ticket is open and under consideration. Is there a viable workaround in place until such a time that it is addressed? As described in the ticket, I'd like to declare packages to scan for a groovy function. (along the lines of what is already supported for Application context builder or MicronautTest)