Skip to content

Non-static method is being referenced from a static context in generate __BeanDefinitions.java while processing AOT #44916

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

Closed
woderchen opened this issue Mar 27, 2025 · 7 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@woderchen
Copy link

woderchen commented Mar 27, 2025

Hi, I encountered an issue with Spring AOT. Please help me confirm if this is a bug. Thanks.
【what to do】
generate native file based on Springboot and GraalVM
【issue】:
Once running "mvn -Pnative native:compile",the message appears:
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.4.3:process-aot (process-aot) ...
non-static method getMqMap() cannot be referenced from a static context MqConfig__BeanDefinitions.java

open MqConfig__BeanDefinitions.java in target/spring-aot:

@Generated
public class MqConfig__BeanDefinitions {
  @SuppressWarnings({"rawtypes", "unchecked"})
  Map getMqMap() {
    Map map = new LinkedHashMap(1);
    map.put("topic", "topic1");
    return map;
  }

  public static BeanDefinition getMqBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(MqConfig.class);
    beanDefinition.getPropertyValues().addPropertyValue("namespace", "mq1");
    beanDefinition.getPropertyValues().addPropertyValue("servers", "1.1.1.1");
    beanDefinition.getPropertyValues().addPropertyValue("config", getMqMap());
    beanDefinition.setInstanceSupplier(MqConfig::new);
    return beanDefinition;
  }
}

------------refre to my codes and environment as below-------------
env: macos 14.1, springboot(spring-boot-maven-plugin) 3.4.3,Liberica-NIK-23.1.6-1,maven 3.6.3

  1. The relevant content of application.yml is as follows:
akso:
  mq:
    configs:
      - namespace: "mq1"
        servers: "1.1.1.1"
        config:
          topic: "topic1"
  1. MqConfig.java:
public class MqConfig {
    private String namespace;
    private String servers;
    private Map<String, String> config;
    ...setter and getter for above parameters...
}

3.AksoMqConfiguration.java

@Configuration
@ConfigurationProperties(prefix = "akso.mq")
@Import(ImportMqConfig.class)
public class AksoMqConfiguration {
    private List<MqConfig> configs;
    ...setter and getter for above parameters...
}
  1. ImportMqConfig.java
public class ImportMqConfig implements ImportBeanDefinitionRegistrar, EnvironmentAware {
    private AksoMqConfiguration configuration;
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        for (MqConfig config : configuration.getConfigs()) {
            RootBeanDefinition beanDefinition = new RootBeanDefinition();
            beanDefinition.setBeanClass(MqConfig.class);
            MutablePropertyValues values = new MutablePropertyValues();
            values.addPropertyValue("namespace", config.getNamespace());
            values.addPropertyValue("servers", config.getServers());
            values.addPropertyValue("config", config.getConfig()); //=>if i remove this line of code,everything is working.
            beanDefinition.setPropertyValues(values);
            registry.registerBeanDefinition(config.getNamespace(), beanDefinition);
        }
    }
    @Override
    public void setEnvironment(Environment environment) {
        String propertiesName = Objects.requireNonNull(AnnotationUtils.getAnnotation(AksoMqConfiguration.class, ConfigurationProperties.class)).prefix();
        configuration = Binder.get(environment).bind(propertiesName, AksoMqConfiguration.class).get();
    }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 27, 2025
@snicoll
Copy link
Member

snicoll commented Mar 27, 2025

The method must be static, yet and Whoever is generating that code should take that into account. Considering we're not the ones generating this code, I am going to close this. Please report that to them.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2025
@snicoll snicoll added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 27, 2025
@woderchen
Copy link
Author

Thanks for your comments. I noticed that the code was generated by spring-boot-maven-plugin. Could you please tell me which team I should report this to?

@snicoll
Copy link
Member

snicoll commented Mar 27, 2025

I noticed that the code was generated by spring-boot-maven-plugin.

It does not. The plugin invokes Spring AOT and components are contributing code. As I've mentioned before, we're not contributing that code. I don't know what AksoMq is but it very much looks like they have a broken AOT integration.

@woderchen

This comment has been minimized.

@snicoll

This comment has been minimized.

@snicoll
Copy link
Member

snicoll commented Mar 27, 2025

Ugh. I just saw something that Spring Framework does that could be related only if the map is a LinkedHashMap which explains why this could have been left unnoticed. I'll create an issue there to investigate.

@woderchen sorry about that and please subscribe to spring-projects/spring-framework#34659

@woderchen
Copy link
Author

No worries, thanks for looking into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants