Skip to content

Custom annotation including RequiresBean is not recognised across modules #768

Closed
@literallyEllie

Description

@literallyEllie

Hi! Just a note this definitely worked in an earlier version (9.12 I believe), however in a new project using 11.1 it no longer works.

Example, within Project A

@Target(ElementType.TYPE)
@RequiresBean(MyBean.class)
public @interface RequiresMyBean {}

Project B:

@Singleton
@RequiresMyBean // <-- ineffective
@RequiresBean(MyBean.class) // <-- Required as RequiresMyBean does nothing. If I was to not have this, I would get [see error below]
public final class SomethingThatRequiresMyBean {

Error without the extra annotation:

Exception in thread "main" java.lang.IllegalStateException: Injecting null for com.project.a.MyBean name:!datasource when creating class com.project.b.SomethingThatRequiresMyBean - potential beans to inject: []. Check for missing module? [ missing beanScopeBuilder.modules() ]. If it is expected to be externally provided, missing beanScopeBuilder.bean() ?
	at io.avaje.inject.spi.DBuilder.getBean(DBuilder.java:386)
	at io.avaje.inject.spi.DBuilder.get(DBuilder.java:333)
	at com.project.b.SomethingThatRequiresMyBean$DI.build(SomethingThatRequiresMyBean$DI.java:13)
	at com.project.b.SomethingThatRequiresMyBeanModule.java.build_probe_SomethingThatRequiresMyBean (SomethingThatRequiresMyBeanModule.java:77)
	at com.project.b.SomethingThatRequiresMyBeanModule.java.build(SomethingThatRequiresMyBeanModule.java:64)

SomethingThatRequiresMyBean Module file:

    public static void build(Builder builder) {
        if (builder.contains(MyBean.class)) { // <--- This is not there without the extra annotation.
            if (builder.isBeanAbsent(new Type[]{SomethingThatRequiresMyBean.class})) {
                SomethingThatRequiresMyBean bean = new SomethingThatRequiresMyBean((MyBean)builder.get(MyBean.class, "!datasource"));
                builder.register(bean);
            }

        }
    }

Let me know if you need any more information. Thank you so much for your work.
Ellie

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions