Closed sdelamo closed 2 years ago
Given that the bean requirements should be evaluated at build time, I would expect this to work. Let me check.
maybe we are not evaluating package-info.java
?
The problem isn't with the package-info.java
class as I can see that the bean is discarded properly (you can check the logs in build/native/jit/logs
and see that there's a line:
Skipping class io.micronaut.views.csp.$BeanConfiguration because it doesn't match bean requirements
Which corresponds to the evaluation of the @Requires
condition of that bean. The problem is more that CspConfiguration$Definition
on its side is evaluated to true so the bean is loaded.
please note that if you run the app with run and visit localhost:8080 it behaves fine
are you suggesting this
@Configuration
@Requires(property = CspConfiguration.PREFIX + ".enabled", value = StringUtils.TRUE)
package io.micronaut.views.csp;
Should be
@Configuration
@Requires(property = CspConfiguration.PREFIX + ".enabled", value = StringUtils.TRUE, defaultValue=StringUtils.FALSE)
package io.micronaut.views.csp;
with defaultValue
set to false
I am not suggesting anything, I'm simply describing what the problem is. Most likely AOT doesn't reproduce a behavior which exists when running the app normally. I'm trying to understand what I need to add to replicate this behavior.
Issue description
I am trying to use micronaut-aot with the micronaut application I am developing as part of Micronaut Live.
Steps to reproduce.
aot
convertYamlToJava = true
https://github.com/micronaut-advocacy/micronaut-live-newsletter/blob/master/README.md#local-development
./gradlew optimizedRun
and open localhost:8080 in your browser. You will get:The CSP beans should not be loaded unless
micronaut.views.csp.enabled
is set totrue
https://github.com/micronaut-projects/micronaut-views/blob/master/views-core/src/main/java/io/micronaut/views/csp/package-info.java#L23
Beans Configurations is a pattern we use heavily through the framework and I think micronaut-aot is not compatible with it yet.
This is my build config: