jamesfredley commented on code in PR #15411: URL: https://github.com/apache/grails-core/pull/15411#discussion_r2827779187
########## grails-test-examples/micronaut/src/integration-test/groovy/micronaut/MicronautBeanTypesSpec.groovy: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package micronaut + +import bean.injection.AppConfig +import bean.injection.FactoryCreatedService +import bean.injection.JavaSingletonService + +import grails.testing.mixin.integration.Integration +import org.springframework.beans.factory.annotation.Autowired +import spock.lang.Specification + +/** + * Integration tests for various Micronaut bean registration mechanisms in Grails context. + * + * Tests that: + * 1. Java @Singleton beans (processed via annotation processor) are available in Spring context + * 2. Groovy @Factory/@Bean beans (processed via AST transform) are available in Spring context + * 3. @ConfigurationProperties beans reflect Grails application.yml config into Micronaut + */ +@Integration +class MicronautBeanTypesSpec extends Specification { + + @Autowired + JavaSingletonService javaSingletonService + + @Autowired + FactoryCreatedService factoryCreatedService + + @Autowired + AppConfig appConfig + + void "Java @Singleton bean is available via Spring autowiring"() { + expect: "bean is injected and functional" + javaSingletonService != null + javaSingletonService.message == 'from-java-singleton' + } + + void "Groovy @Factory/@Bean created bean is available via Spring autowiring"() { + expect: "bean is injected with factory-configured values" + factoryCreatedService != null + factoryCreatedService.name == 'factory-created' + } + + void "@ConfigurationProperties bean reflects application.yml config"() { + expect: "config properties are bound from application.yml" + appConfig != null + appConfig.name == 'test-micronaut-app' + } + + void "Java @Singleton bean is a singleton instance"() { + when: + def first = javaSingletonService + def second = javaSingletonService + + then: "same instance is returned" + first.is(second) + } + + void "Factory-created bean is a singleton instance"() { + when: + def first = factoryCreatedService + def second = factoryCreatedService + + then: "same instance is returned (factory method annotated with @Singleton)" + first.is(second) + } Review Comment: Fixed - both singleton tests now use `applicationContext.getBean()` to retrieve the bean twice independently, which properly verifies singleton scope. ########## grails-test-examples/micronaut/grails-app/controllers/micronaut/MicronautTestController.groovy: ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package micronaut + +import bean.injection.AppConfig +import bean.injection.FactoryCreatedService +import bean.injection.JavaSingletonService +import bean.injection.NamedService +import groovy.transform.CompileStatic + +import org.springframework.beans.factory.annotation.Autowired + +@CompileStatic +class MicronautTestController { + + @Autowired + JavaSingletonService javaSingletonService + + @Autowired + FactoryCreatedService factoryCreatedService + + @Autowired + AppConfig appConfig + + @Autowired + NamedService namedService + + def index() { + render(contentType: 'application/json', text: [ + javaMessage: javaSingletonService.message, + factoryName: factoryCreatedService.name, + appName: appConfig.name, + namedService: namedService.name + ]) Review Comment: Fixed - changed to `render([...] as JSON)` with `import grails.converters.JSON`, matching the established pattern used across the codebase. ########## grails-test-examples/micronaut/src/main/java/bean/injection/JavaSingletonService.java: ########## @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package bean.injection; + +import jakarta.inject.Singleton; + +interface JavaMessageProvider { + + String getMessage(); + +} + +@Singleton +public class JavaSingletonService implements JavaMessageProvider { + + @Override Review Comment: Fixed - made `JavaMessageProvider` public and added a new test `"Java @Singleton bean is resolvable by its interface type"` in `MicronautBeanTypesSpec` that exercises interface-type injection, verifying the bean is found and is the same singleton instance. ########## grails-doc/src/en/guide/upgrading/upgrading60x.adoc: ########## @@ -371,6 +371,12 @@ Here's an example `gradle.properties` file: micronautPlatformVersion=4.9.2 ---- +Please note that due to https://github.com/micronaut-projects/micronaut-spring/issues/769[this issue], Spring Boot Dev tools does not work with the micronaut integration. Review Comment: Fixed - corrected to "Spring Boot DevTools" and "Micronaut integration" with the grammar tightened as suggested. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
