├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yaml │ ├── config.yml │ ├── new_feature.yaml │ └── other.yaml ├── release.yml ├── renovate.json └── workflows │ ├── central-sync.yml │ ├── graalvm-dev.yml │ ├── graalvm-latest.yml │ ├── gradle.yml │ ├── publish-snapshot.yml │ └── release.yml ├── .gitignore ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── MAINTAINING.md ├── README.md ├── SECURITY.md ├── build.gradle ├── buildSrc ├── build.gradle ├── settings.gradle └── src │ └── main │ └── groovy │ ├── io.micronaut.build.internal.spring-base.gradle │ ├── io.micronaut.build.internal.spring-module.gradle │ └── io.micronaut.build.internal.spring-tests.gradle ├── config ├── HEADER ├── accepted-api-changes.json ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml └── spotless.license.java ├── gradle.properties ├── gradle ├── libs.versions.toml ├── license.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── spring-annotation ├── build.gradle └── src │ └── main │ ├── java │ └── io │ │ └── micronaut │ │ └── spring │ │ └── annotation │ │ ├── AbstractSpringAnnotationMapper.java │ │ ├── beans │ │ ├── ImportAnnotationMapper.java │ │ └── ImportAnnotationVisitor.java │ │ ├── cache │ │ ├── CacheEvictAnnotationMapper.java │ │ ├── CachePutAnnotationMapper.java │ │ └── CacheableAnnotationMapper.java │ │ ├── context │ │ ├── AutowiredAnnotationMapper.java │ │ ├── BeanAnnotationMapper.java │ │ ├── ComponentAnnotationMapper.java │ │ ├── ConfigurationAnnotationMapper.java │ │ ├── FallbackAnnotationMapper.java │ │ ├── LazyAnnotationMapper.java │ │ ├── PrimaryAnnotationMapper.java │ │ ├── ProfileAnnotationMapper.java │ │ ├── QualifierAnnotationMapper.java │ │ ├── RepositoryAnnotationMapper.java │ │ ├── ServiceAnnotationMapper.java │ │ └── ValueAnnotationMapper.java │ │ ├── event │ │ └── EventListenerAnnotationMapper.java │ │ ├── scheduling │ │ ├── AsyncAnnotationMapper.java │ │ └── ScheduledAnnotationMapper.java │ │ ├── tx │ │ └── TransactionalAnnotationMapper.java │ │ └── validation │ │ └── ValidatedAnnotationMapper.java │ └── resources │ └── META-INF │ └── services │ ├── io.micronaut.inject.annotation.AnnotationMapper │ └── io.micronaut.inject.visitor.TypeElementVisitor ├── spring-bom └── build.gradle ├── spring-boot-annotation ├── build.gradle └── src │ └── main │ ├── java │ └── io │ │ └── micronaut │ │ └── spring │ │ └── boot │ │ └── annotation │ │ ├── ConditionalOnBeanAnnotationMapper.java │ │ ├── ConditionalOnClassAnnotationMapper.java │ │ ├── ConditionalOnMissingBeanAnnotationMapper.java │ │ ├── ConditionalOnMissingClassAnnotationMapper.java │ │ ├── ConditionalOnNotWebApplicationAnnotationMapper.java │ │ ├── ConditionalOnPropertyAnnotationMapper.java │ │ ├── ConditionalOnSingleCandidateAnnotationMapper.java │ │ ├── ConditionalOnWebApplicationAnnotationMapper.java │ │ ├── ConfigurationPropertiesAnnotationMapper.java │ │ ├── DeleteOperationAnnotationMapper.java │ │ ├── EndpointAnnotationMapper.java │ │ ├── ReadOperationAnnotationMapper.java │ │ ├── SelectorAnnotationMapper.java │ │ └── WriteOperationAnnotationMapper.java │ └── resources │ └── META-INF │ └── services │ └── io.micronaut.inject.annotation.AnnotationMapper ├── spring-boot-starter ├── build.gradle └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── micronaut │ │ │ └── spring │ │ │ └── boot │ │ │ └── starter │ │ │ ├── EnableMicronaut.java │ │ │ ├── MicronautBeanFilter.java │ │ │ └── MicronautImportRegistrar.java │ └── resources │ │ └── META-INF │ │ └── spring │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ └── test │ └── java │ └── io │ └── micronaut │ └── spring │ └── boot │ ├── autconfigure │ └── AutoConfigureMicronautTest.java │ ├── customautoconfigure │ └── CustomAutoConfigureMicronautTest.java │ └── starter │ └── EnableMicronautTest.java ├── spring-boot ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── micronaut │ │ └── spring │ │ └── boot │ │ ├── ApplicationRunnerListener.java │ │ └── condition │ │ ├── RequiresSingleCandidate.java │ │ └── RequiresSingleCandidateCondition.java │ └── test │ ├── groovy │ └── io │ │ └── micronaut │ │ └── spring │ │ └── boot │ │ ├── EndpointSpec.groovy │ │ ├── SpringApplicationBuilderSpec.groovy │ │ └── annotation │ │ ├── ConfigurationPropertiesSpec.groovy │ │ └── condition │ │ └── ConditionalOnSpec.groovy │ ├── java │ ├── io │ │ └── micronaut │ │ │ └── spring │ │ │ └── boot │ │ │ ├── MyComponent.java │ │ │ ├── TestController.java │ │ │ └── annotation │ │ │ ├── MyConfigurationProperties.java │ │ │ └── condition │ │ │ ├── ConditionalOnBeanComponent.java │ │ │ ├── ConditionalOnBeanComponent2.java │ │ │ ├── ConditionalOnClassComponent.java │ │ │ ├── ConditionalOnMissingBeanComponent.java │ │ │ ├── ConditionalOnMissingBeanComponent2.java │ │ │ ├── ConditionalOnNotWebApplicationComponent.java │ │ │ ├── ConditionalOnPropertyBean.java │ │ │ ├── ConditionalOnPropertyBean2.java │ │ │ ├── ConditionalOnPropertyBean3.java │ │ │ ├── ConditionalOnPropertyBean4.java │ │ │ ├── ConditionalOnSingleCandidateComponent.java │ │ │ ├── ConditionalOnSingleCandidateComponent2.java │ │ │ └── ConditionalOnWebApplicationComponent.java │ └── some │ │ └── other │ │ └── pkg │ │ ├── FeaturesClient.java │ │ ├── FeaturesEndpoint.java │ │ ├── MyOtherComponent.java │ │ └── TestClient.java │ └── resources │ └── logback-test.xml ├── spring-context ├── build.gradle └── src │ ├── main │ └── java │ │ └── io │ │ └── micronaut │ │ └── spring │ │ └── context │ │ ├── ManagedApplicationContext.java │ │ ├── MicronautApplicationContext.java │ │ ├── aop │ │ ├── SpringConfigurationAdvice.java │ │ └── SpringConfigurationInterceptor.java │ │ ├── aware │ │ └── SpringAwareListener.java │ │ ├── convert │ │ └── MicronautConversionService.java │ │ ├── env │ │ └── MicronautEnvironment.java │ │ ├── event │ │ ├── ContextEventAdapter.java │ │ └── MicronautApplicationEventPublisher.java │ │ └── factory │ │ ├── ImportBeanRegistrarProcessor.java │ │ ├── MicronautBeanFactory.java │ │ └── MicronautBeanFactoryConfiguration.java │ └── test │ ├── groovy │ └── io │ │ └── micronaut │ │ └── spring │ │ ├── annotation │ │ └── context │ │ │ ├── ApplicationContextSpec.groovy │ │ │ ├── BeanFactorySpec.groovy │ │ │ ├── CacheAnnotationMappingSpec.groovy │ │ │ ├── ConfigurationAnnotationMappingSpec.groovy │ │ │ ├── FallbackSpec.groovy │ │ │ ├── ImportAnnotationSpec.groovy │ │ │ ├── MicronautBeanFactoryConfigurationSpec.groovy │ │ │ ├── ParameterizedBeanSpec.groovy │ │ │ ├── ParentApplicationContextSpec.groovy │ │ │ ├── ProfileAnnotationMapperSpec.groovy │ │ │ ├── QualifierSpec.groovy │ │ │ └── SimpleConfigurationSpec.groovy │ │ └── core │ │ └── type │ │ └── SpringMetadataSpec.groovy │ ├── java │ └── io │ │ └── micronaut │ │ └── spring │ │ └── annotation │ │ └── context │ │ ├── MyComponent.java │ │ ├── MyConfiguration.java │ │ ├── MyFallback.java │ │ ├── MyInterface.java │ │ ├── MyInterfaceImpl.java │ │ ├── MyJob.java │ │ ├── MyNamedService.java │ │ └── MyTransactionalService.java │ └── resources │ └── logback-test.xml ├── spring-web-annotation ├── build.gradle └── src │ └── main │ ├── java │ └── io │ │ └── micronaut │ │ └── spring │ │ └── web │ │ └── annotation │ │ ├── CookieValueAnnotationMapper.java │ │ ├── DeleteMappingAnnotationTransformer.java │ │ ├── ExceptionHandlerAnnotationMapper.java │ │ ├── GetMappingAnnotationTransformer.java │ │ ├── PatchMappingAnnotationTransformer.java │ │ ├── PathVariableAnnotationMapper.java │ │ ├── PostMappingAnnotationTransformer.java │ │ ├── PutMappingAnnotationTransformer.java │ │ ├── RequestAttributeAnnotationMapper.java │ │ ├── RequestBodyAnnotationMapper.java │ │ ├── RequestHeaderAnnotationMapper.java │ │ ├── RequestMappingAnnotationTransformer.java │ │ ├── RequestParamAnnotationMapper.java │ │ ├── RequestPartAnnotationMapper.java │ │ ├── ResponseStatusAnnotationMapper.java │ │ ├── RestControllerAnnotationMapper.java │ │ ├── WebBindAnnotationMapper.java │ │ └── exchange │ │ ├── DeleteExchangeAnnotationTransformer.java │ │ ├── GetExchangeAnnotationTransformer.java │ │ ├── HttpExchangeAnnotationTransformer.java │ │ ├── PatchExchangeAnnotationTransformer.java │ │ ├── PostExchangeAnnotationTransformer.java │ │ └── PutExchangeAnnotationTransformer.java │ └── resources │ └── META-INF │ └── services │ ├── io.micronaut.inject.annotation.AnnotationMapper │ └── io.micronaut.inject.annotation.AnnotationTransformer ├── spring-web ├── build.gradle └── src │ ├── main │ └── java │ │ └── io │ │ └── micronaut │ │ └── spring │ │ └── web │ │ ├── ModelAndViewServerFilter.java │ │ ├── ResponseEntityServerFilter.java │ │ ├── bind │ │ ├── HttpMethodArgumentBinder.java │ │ ├── ModelMapRequestArgumentBinder.java │ │ ├── ModelRequestArgumentBinder.java │ │ ├── RequestAttributeArgumentBinder.java │ │ └── ServerHttpRequestBinder.java │ │ └── reactive │ │ ├── ChannelResolver.java │ │ ├── DefaultChannelResolver.java │ │ ├── MicronautNettyChannelResolver.java │ │ └── MicronautServerHttpRequest.java │ └── test │ ├── groovy │ └── io │ │ └── micronaut │ │ └── spring │ │ └── web │ │ └── annotation │ │ ├── RestControllerSpec.groovy │ │ └── exchange │ │ └── ExchangeControllerSpec.groovy │ ├── java │ └── io │ │ └── micronaut │ │ └── spring │ │ └── web │ │ └── annotation │ │ ├── Greeting.java │ │ ├── GreetingClient.java │ │ ├── GreetingController.java │ │ ├── NestedGreetingController.java │ │ └── exchange │ │ ├── ExchangeGreetingApi.java │ │ ├── ExchangeGreetingClient.java │ │ └── ExchangeGreetingController.java │ └── resources │ ├── logback-test.xml │ └── views │ └── welcome.html ├── spring ├── README.md ├── build.gradle └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── micronaut │ │ │ └── spring │ │ │ ├── beans │ │ │ ├── ImportedBy.java │ │ │ ├── MicronautBeanProcessor.java │ │ │ ├── MicronautContextInternal.java │ │ │ ├── MicronautSpringBeanFactory.java │ │ │ ├── ObjectProviderBeanDefinition.java │ │ │ ├── SpringImport.java │ │ │ ├── aware │ │ │ │ └── ImportAwareListener.java │ │ │ └── package-info.java │ │ │ ├── core │ │ │ ├── annotation │ │ │ │ ├── MergedAnnotationValue.java │ │ │ │ └── MicronautMergedAnnotations.java │ │ │ ├── env │ │ │ │ ├── PropertyResolverAdapter.java │ │ │ │ └── package-info.java │ │ │ ├── event │ │ │ │ ├── ApplicationEventPublisherAdapter.java │ │ │ │ └── package-info.java │ │ │ └── type │ │ │ │ ├── BeanDefinitionSpringMetadata.java │ │ │ │ └── ClassElementSpringMetadata.java │ │ │ └── tx │ │ │ ├── annotation │ │ │ ├── BindableRuleBasedTransactionAttribute.java │ │ │ ├── TransactionInterceptor.java │ │ │ └── package-info.java │ │ │ └── test │ │ │ └── SpringTransactionTestExecutionListener.java │ └── resources │ │ └── META-INF │ │ └── micronaut │ │ └── io.micronaut.inject.BeanDefinitionReference │ │ └── io.micronaut.spring.beans.ObjectProviderBeanDefinition │ └── test │ ├── groovy │ └── io │ │ └── micronaut │ │ └── spring │ │ └── beans │ │ ├── MicronautBeanProcessorByAnnotationTypeSpec.groovy │ │ └── MicronautBeanProcessorByConcreteTypeSpec.groovy │ └── resources │ └── logback-test.xml ├── src └── main │ └── docs │ └── guide │ ├── introduction.adoc │ ├── micronautInsideSpring.adoc │ ├── micronautInsideSpring │ ├── beanPostProcessor.adoc │ ├── springBootStarter.adoc │ └── springParentContext.adoc │ ├── releaseHistory.adoc │ ├── repository.adoc │ ├── sharingLibraries.adoc │ ├── springGuides.adoc │ ├── springToMicronaut.adoc │ ├── springToMicronaut │ ├── micronautClient.adoc │ ├── springAnnotations.adoc │ ├── springBoot.adoc │ ├── springDataAnnotations.adoc │ ├── springEvents.adoc │ ├── springInterfaces.adoc │ ├── springLimitations.adoc │ ├── springMvc.adoc │ └── springToMicronautStart.adoc │ └── toc.yml └── test-suite ├── build.gradle.kts └── src └── test └── groovy └── io └── micronaut └── spring └── tx ├── EventListenerSpec.groovy ├── FakeEvent.groovy ├── MetaAnnotation.java ├── MetaTransactionalBean.java ├── MockSpringTxSpec.groovy ├── MockTransactionManager.java ├── TransactionalBean.java └── TransactionalListener.java /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space 8 | 9 | [{*.sh,gradlew}] 10 | end_of_line = lf 11 | 12 | [{*.bat,*.cmd}] 13 | end_of_line = crlf 14 | 15 | [{*.mustache,*.ftl}] 16 | insert_final_newline = false 17 | 18 | [*.java] 19 | indent_size = 4 20 | tab_width = 4 21 | max_line_length = 100 22 | # Import order can be configured with ij_java_imports_layout=... 23 | # See documentation https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0 24 | 25 | [*.xml] 26 | indent_size = 4 27 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | *.java text eol=lf 5 | *.groovy text eol=lf 6 | *.html text eol=lf 7 | *.kt text eol=lf 8 | *.kts text eol=lf 9 | *.md text diff=markdown eol=lf 10 | *.py text diff=python executable 11 | *.pl text diff=perl executable 12 | *.pm text diff=perl 13 | *.css text diff=css eol=lf 14 | *.js text eol=lf 15 | *.sql text eol=lf 16 | *.q text eol=lf 17 | 18 | *.sh text eol=lf 19 | gradlew text eol=lf 20 | 21 | *.bat text eol=crlf 22 | *.cmd text eol=crlf 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yaml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report 3 | body: 4 | - type: markdown 5 | attributes: 6 | value: | 7 | Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed. 8 | 9 | NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Github Discussions :arrow_up:, [Stack Overflow](https://stackoverflow.com/tags/micronaut) or [Gitter](https://gitter.im/micronautfw/). 10 | - type: textarea 11 | attributes: 12 | label: Expected Behavior 13 | description: A concise description of what you expected to happen. 14 | placeholder: Tell us what should happen 15 | validations: 16 | required: false 17 | - type: textarea 18 | attributes: 19 | label: Actual Behaviour 20 | description: A concise description of what you're experiencing. 21 | placeholder: Tell us what happens instead 22 | validations: 23 | required: false 24 | - type: textarea 25 | attributes: 26 | label: Steps To Reproduce 27 | description: Steps to reproduce the behavior. 28 | placeholder: | 29 | 1. In this environment... 30 | 2. With this config... 31 | 3. Run '...' 32 | 4. See error... 33 | validations: 34 | required: false 35 | - type: textarea 36 | attributes: 37 | label: Environment Information 38 | description: Environment information where the problem occurs. 39 | placeholder: | 40 | - Operating System: 41 | - JDK Version: 42 | validations: 43 | required: false 44 | - type: input 45 | id: example 46 | attributes: 47 | label: Example Application 48 | description: Example application link. 49 | placeholder: | 50 | Link to GitHub repository with an example that reproduces the issue 51 | validations: 52 | required: false 53 | - type: input 54 | id: version 55 | attributes: 56 | label: Version 57 | description: Micronaut version 58 | validations: 59 | required: true 60 | 61 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Micronaut Core Discussions 3 | url: https://github.com/micronaut-projects/micronaut-core/discussions 4 | about: Ask questions about Micronaut on Github 5 | - name: Micronaut Data Discussions 6 | url: https://github.com/micronaut-projects/micronaut-data/discussions 7 | about: Ask Micronaut Data related questions on Github 8 | - name: Stack Overflow 9 | url: https://stackoverflow.com/tags/micronaut 10 | about: Ask questions on Stack Overflow 11 | - name: Chat 12 | url: https://gitter.im/micronautfw/ 13 | about: Chat with us on Gitter. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new_feature.yaml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Create a new feature request 3 | body: 4 | - type: markdown 5 | attributes: 6 | value: | 7 | Please describe the feature you want for Micronaut to implement, before that check if there is already an existing issue to add it. 8 | - type: textarea 9 | attributes: 10 | label: Feature description 11 | placeholder: Tell us what feature you would like for Micronaut to have and what problem is it going to solve 12 | validations: 13 | required: true 14 | 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other.yaml: -------------------------------------------------------------------------------- 1 | name: Other 2 | description: Something different 3 | body: 4 | - type: textarea 5 | attributes: 6 | label: Issue description 7 | validations: 8 | required: true 9 | 10 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | authors: 4 | - micronaut-build 5 | categories: 6 | - title: Breaking Changes 🛠 7 | labels: 8 | - 'type: breaking' 9 | - title: New Features 🎉 10 | labels: 11 | - 'type: enhancement' 12 | - title: Bug Fixes 🐞 13 | labels: 14 | - 'type: bug' 15 | - title: Improvements ⭐ 16 | labels: 17 | - 'type: improvement' 18 | - title: Docs 📖 19 | labels: 20 | - 'type: docs' 21 | - title: Dependency updates 🚀 22 | labels: 23 | - 'type: dependency-upgrade' 24 | - 'dependency-upgrade' 25 | - title: Regressions 🧐 26 | labels: 27 | - 'type: regression' 28 | - title: GraalVM 🏆 29 | labels: 30 | - 'relates-to: graal' 31 | - title: Other Changes 💡 32 | labels: 33 | - "*" 34 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:recommended" 4 | ], 5 | "addLabels": [ 6 | "type: dependency-upgrade" 7 | ], 8 | "schedule": [ 9 | "after 10pm" 10 | ], 11 | "prHourlyLimit": 1, 12 | "prConcurrentLimit": 20, 13 | "timezone": "Europe/Prague", 14 | "packageRules": [ 15 | { 16 | "dependencyDashboardApproval": true, 17 | "matchUpdateTypes": [ 18 | "patch" 19 | ], 20 | "matchCurrentVersion": "!/^0/", 21 | "automerge": true, 22 | "matchPackageNames": [ 23 | "/actions.*/" 24 | ] 25 | }, 26 | { 27 | "matchUpdateTypes": [ 28 | "patch" 29 | ], 30 | "matchCurrentVersion": "!/^0/", 31 | "automerge": true 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/central-sync.yml: -------------------------------------------------------------------------------- 1 | # WARNING: Do not edit this file directly. Instead, go to: 2 | # 3 | # https://github.com/micronaut-projects/micronaut-project-template/tree/master/.github/workflows 4 | # 5 | # and edit them there. Note that it will be sync'ed to all the Micronaut repos 6 | name: Maven Central Sync 7 | on: 8 | workflow_dispatch: 9 | inputs: 10 | release_version: 11 | description: 'Release version (eg: 1.2.3)' 12 | required: true 13 | jobs: 14 | central-sync: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout repository 18 | uses: actions/checkout@v4 19 | with: 20 | ref: v${{ github.event.inputs.release_version }} 21 | - uses: gradle/wrapper-validation-action@v3 22 | - name: Set up JDK 23 | uses: actions/setup-java@v4 24 | with: 25 | distribution: 'temurin' 26 | java-version: '17' 27 | - name: Publish to Sonatype OSSRH 28 | env: 29 | SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 30 | SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 31 | GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} 32 | GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} 33 | GPG_FILE: ${{ secrets.GPG_FILE }} 34 | DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} 35 | DEVELOCITY_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }} 36 | DEVELOCITY_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }} 37 | run: | 38 | echo $GPG_FILE | base64 -d > secring.gpg 39 | ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository 40 | -------------------------------------------------------------------------------- /.github/workflows/publish-snapshot.yml: -------------------------------------------------------------------------------- 1 | # WARNING: Do not edit this file directly. Instead, go to: 2 | # 3 | # https://github.com/micronaut-projects/micronaut-project-template/tree/master/.github/workflows 4 | # 5 | # and edit them there. Note that it will be sync'ed to all the Micronaut repos 6 | name: Publish snapshot release 7 | on: [workflow_dispatch] 8 | jobs: 9 | build: 10 | if: github.repository != 'micronaut-projects/micronaut-project-template' 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: actions/cache@v4 15 | with: 16 | path: ~/.gradle/caches 17 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} 18 | restore-keys: | 19 | ${{ runner.os }}-gradle- 20 | - name: Set up JDK 21 | uses: actions/setup-java@v4 22 | with: 23 | distribution: 'temurin' 24 | java-version: '17' 25 | - name: Publish to Sonatype Snapshots 26 | if: success() 27 | env: 28 | SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 29 | SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 30 | DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} 31 | DEVELOCITY_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }} 32 | DEVELOCITY_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }} 33 | run: ./gradlew publishToSonatype --no-daemon 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | .DS_Store 3 | target/ 4 | .gradle/ 5 | .idea/ 6 | build/ 7 | !build-logic/src/main/java/io/micronaut/build 8 | classes/ 9 | out/ 10 | *.db 11 | *.log 12 | *.iml 13 | .classpath 14 | .factorypath 15 | bin/ 16 | .settings/ 17 | .project 18 | */test/ 19 | */META-INF/ 20 | *.ipr 21 | *.iws 22 | .kotlintest 23 | */.kotlintest/ 24 | 25 | # ignore resources, are downloaded via a gradle task from micronaut_docs 26 | src/main/docs/resources/css/highlight/*.css 27 | src/main/docs/resources/css/highlight/*.png 28 | src/main/docs/resources/css/highlight/*.jpg 29 | src/main/docs/resources/css/*.css 30 | src/main/docs/resources/js/*.js 31 | src/main/docs/resources/style/*.html 32 | src/main/docs/resources/img/micronaut-logo-white.svg 33 | 34 | # Ignore files generated by test-resources 35 | **/.micronaut/test-resources/ 36 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thanks for reporting an issue, please review the task list below before submitting the 2 | issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed. 3 | 4 | NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (https://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions. 5 | 6 | ### Task List 7 | 8 | - [ ] Steps to reproduce provided 9 | - [ ] Stacktrace (if present) provided 10 | - [ ] Example that reproduces the problem uploaded to Github 11 | - [ ] Full description of the issue provided (see below) 12 | 13 | ### Steps to Reproduce 14 | 15 | 1. TODO 16 | 2. TODO 17 | 3. TODO 18 | 19 | ### Expected Behaviour 20 | 21 | Tell us what should happen 22 | 23 | ### Actual Behaviour 24 | 25 | Tell us what happens instead 26 | 27 | ### Environment Information 28 | 29 | - **Operating System**: TODO 30 | - **Micronaut Version:** TODO 31 | - **JDK Version:** TODO 32 | 33 | ### Example Application 34 | 35 | - TODO: link to github repository with example that reproduces the issue 36 | 37 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | We release patches for security vulnerabilities. Which versions are eligible 4 | receiving such patches depend on the CVSS v3.0 Rating: 5 | 6 | | CVSS v3.0 | Supported Versions | 7 | |-----------|-------------------------------------------| 8 | | 9.0-10.0 | Releases within the previous three months | 9 | | 4.0-8.9 | Most recent release | 10 | 11 | ## Reporting a Vulnerability 12 | 13 | Please responsibly disclose (suspected) security vulnerabilities to 14 | **[The Micronaut Foundation](foundation@micronaut.io)**. You will receive a response from 15 | us within 48 hours. If the issue is confirmed, we will release a patch as soon 16 | as possible depending on complexity but historically within a few days. 17 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.docs' 3 | id 'io.micronaut.build.internal.quality-reporting' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'groovy-gradle-plugin' 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation(libs.sonatype.scan) 11 | } 12 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle: -------------------------------------------------------------------------------- 1 | dependencyResolutionManagement { 2 | versionCatalogs { 3 | libs { 4 | from(files("../gradle/libs.versions.toml")) 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/io.micronaut.build.internal.spring-base.gradle: -------------------------------------------------------------------------------- 1 | repositories { 2 | mavenCentral() 3 | } 4 | 5 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/io.micronaut.build.internal.spring-module.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-base' 3 | id 'io.micronaut.build.internal.module' 4 | id("org.sonatype.gradle.plugins.scan") 5 | } 6 | String ossIndexUsername = System.getenv("OSS_INDEX_USERNAME") ?: project.properties["ossIndexUsername"] 7 | String ossIndexPassword = System.getenv("OSS_INDEX_PASSWORD") ?: project.properties["ossIndexPassword"] 8 | boolean sonatypePluginConfigured = ossIndexUsername != null && ossIndexPassword != null 9 | if (sonatypePluginConfigured) { 10 | ossIndexAudit { 11 | username = ossIndexUsername 12 | password = ossIndexPassword 13 | } 14 | } 15 | 16 | repositories { 17 | mavenCentral() 18 | } 19 | 20 | dependencies { 21 | api(platform(libs.boms.spring)) 22 | testImplementation(platform(libs.boms.spring)) 23 | //compileOnly 'com.google.code.findbugs:jsr305' // for "warning: unknown enum constant When.MAYBE" 24 | //testCompileOnly 'com.google.code.findbugs:jsr305' // for "warning: unknown enum constant When.MAYBE" 25 | } 26 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/io.micronaut.build.internal.spring-tests.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-base' 3 | } 4 | -------------------------------------------------------------------------------- /config/HEADER: -------------------------------------------------------------------------------- 1 | Copyright ${year} original authors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /config/spotless.license.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-$YEAR original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | projectVersion=5.10.2-SNAPSHOT 2 | projectGroup=io.micronaut.spring 3 | 4 | title=Micronaut for Spring 5 | projectDesc=Extensions to integrate Micronaut and Spring 6 | projectUrl=https://micronaut.io 7 | githubSlug=micronaut-projects/micronaut-spring 8 | developers=Graeme Rocher 9 | 10 | springbootapi=https://docs.spring.io/spring-boot/docs/current/api 11 | springdataapi=https://docs.spring.io/spring-data/data-commons/docs/current/api 12 | micronautcache=https://micronaut-projects.github.io/micronaut-cache/latest/api 13 | micronautspringapi=https://micronaut-projects.github.io/micronaut-spring/latest/api 14 | micronautdataapi=https://micronaut-projects.github.io/micronaut-data/latest/api 15 | -------------------------------------------------------------------------------- /gradle/license.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.hierynomus.license' 2 | 3 | license { 4 | header = rootProject.file('config/HEADER') 5 | strictCheck = true 6 | ignoreFailures = true 7 | mapping { 8 | kt = 'SLASHSTAR_STYLE' 9 | java = 'SLASHSTAR_STYLE' 10 | groovy = 'SLASHSTAR_STYLE' 11 | } 12 | ext.year = '2017-2020' 13 | 14 | exclude "**/transaction/**" 15 | exclude '**/*.txt' 16 | exclude '**/*.html' 17 | exclude '**/*.xml' 18 | exclude '**/*.json' 19 | exclude '**/build-info.properties' 20 | exclude '**/git.properties' 21 | exclude '**/othergit.properties' 22 | } 23 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micronaut-projects/micronaut-spring/9ef83225e81d4def76607327886d98488a465734/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | mavenCentral() 5 | } 6 | } 7 | 8 | plugins { 9 | id 'io.micronaut.build.shared.settings' version '7.3.2' 10 | } 11 | 12 | rootProject.name = 'spring-parent' 13 | 14 | include 'spring' 15 | include 'spring-annotation' 16 | include 'spring-bom' 17 | include 'spring-boot-annotation' 18 | include 'spring-boot' 19 | include 'spring-boot-starter' 20 | include 'spring-web-annotation' 21 | include 'spring-web' 22 | include 'spring-context' 23 | include 'test-suite' 24 | 25 | enableFeaturePreview 'TYPESAFE_PROJECT_ACCESSORS' 26 | 27 | micronautBuild { 28 | useStandardizedProjectNames = true 29 | importMicronautCatalog() 30 | importMicronautCatalog("micronaut-cache") 31 | importMicronautCatalog("micronaut-views") 32 | importMicronautCatalog("micronaut-validation") 33 | importMicronautCatalog("micronaut-servlet") 34 | } 35 | -------------------------------------------------------------------------------- /spring-annotation/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-module' 3 | } 4 | 5 | dependencies { 6 | api platform(libs.boms.spring) 7 | api mn.micronaut.inject 8 | api mn.micronaut.aop 9 | api mnValidation.micronaut.validation 10 | 11 | implementation mnValidation.micronaut.validation.processor 12 | implementation mn.micronaut.core.processor 13 | implementation projects.micronautSpring 14 | implementation projects.micronautSpringContext 15 | implementation mn.micronaut.runtime 16 | implementation mnCache.micronaut.cache.core 17 | 18 | testAnnotationProcessor mn.micronaut.inject.java 19 | 20 | testImplementation mn.micronaut.inject.groovy 21 | testImplementation projects.micronautSpring 22 | testImplementation libs.managed.spring.tx 23 | } 24 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/AbstractSpringAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.NonNull; 20 | import io.micronaut.inject.annotation.NamedAnnotationMapper; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | /** 28 | * Abstract mapper for Spring annotations. 29 | * 30 | * @author graemerocher 31 | * @since 1.0 32 | */ 33 | public abstract class AbstractSpringAnnotationMapper implements NamedAnnotationMapper { 34 | @Override 35 | public final List> map(AnnotationValue annotation, VisitorContext visitorContext) { 36 | if (annotation == null || visitorContext == null) { 37 | return Collections.emptyList(); 38 | } 39 | 40 | return mapInternal(annotation, visitorContext); 41 | } 42 | 43 | /** 44 | * Internal map implemenation that subclasses should implement. 45 | * @param annotation The annotation 46 | * @param visitorContext The visitor context 47 | * @return A list of annotations 48 | */ 49 | protected abstract @NonNull List> mapInternal( 50 | @NonNull AnnotationValue annotation, 51 | @NonNull VisitorContext visitorContext); 52 | } 53 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/beans/ImportAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.beans; 17 | 18 | import java.util.Arrays; 19 | import java.util.List; 20 | 21 | import io.micronaut.context.annotation.Bean; 22 | import io.micronaut.core.annotation.Internal; 23 | import org.springframework.context.annotation.Import; 24 | 25 | import io.micronaut.core.annotation.AnnotationMetadata; 26 | import io.micronaut.core.annotation.AnnotationValue; 27 | import io.micronaut.inject.annotation.TypedAnnotationMapper; 28 | import io.micronaut.inject.visitor.VisitorContext; 29 | 30 | /** 31 | * Maps {@code io.micronaut.spring.beans.SpringImport} to Micronaut Framework {@link Import} annotation. 32 | * @author graemerocher 33 | * @since 4.3.0 34 | */ 35 | @Internal 36 | public final class ImportAnnotationMapper implements TypedAnnotationMapper { 37 | 38 | @Override 39 | public Class annotationType() { 40 | return Import.class; 41 | } 42 | 43 | @Override 44 | public List> map(AnnotationValue annotation, VisitorContext visitorContext) { 45 | return Arrays.asList( 46 | AnnotationValue.builder(ImportAnnotationVisitor.IMPORT_ANNOTATION) 47 | .member(AnnotationMetadata.VALUE_MEMBER, annotation.annotationClassValues(AnnotationMetadata.VALUE_MEMBER)) 48 | .build(), 49 | annotation, 50 | AnnotationValue.builder(Bean.class).build() 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/cache/CacheEvictAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.cache; 17 | 18 | import io.micronaut.cache.annotation.CacheInvalidate; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.core.annotation.AnnotationValueBuilder; 21 | import io.micronaut.core.annotation.NonNull; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps the Spring cache annotations. 27 | * 28 | * @since 1.0 29 | * @author graemerocher 30 | */ 31 | public class CacheEvictAnnotationMapper extends CacheableAnnotationMapper { 32 | 33 | @Override 34 | public String getName() { 35 | return "org.springframework.cache.annotation.CacheEvict"; 36 | } 37 | 38 | @Override 39 | protected @NonNull AnnotationValueBuilder buildAnnotation() { 40 | return AnnotationValue.builder(CacheInvalidate.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/cache/CachePutAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.cache; 17 | 18 | import io.micronaut.cache.annotation.CachePut; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.core.annotation.AnnotationValueBuilder; 21 | import io.micronaut.core.annotation.NonNull; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps the Spring cache annotations. 27 | * 28 | * @since 1.0 29 | * @author graemerocher 30 | */ 31 | public class CachePutAnnotationMapper extends CacheableAnnotationMapper { 32 | 33 | @Override 34 | public String getName() { 35 | return "org.springframework.cache.annotation.CachePut"; 36 | } 37 | 38 | @Override 39 | protected @NonNull AnnotationValueBuilder buildAnnotation() { 40 | return AnnotationValue.builder(CachePut.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/AutowiredAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.core.annotation.AnnotationUtil; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.core.annotation.Nullable; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * Maps {@code @Autowired} to javax.inject.Inject. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class AutowiredAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.beans.factory.annotation.Autowired"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | final boolean required = annotation.getValue(Boolean.class).orElse(true); 43 | 44 | List> annotations = new ArrayList<>(2); 45 | annotations.add(AnnotationValue.builder(AnnotationUtil.INJECT).build()); 46 | if (!required) { 47 | annotations.add(AnnotationValue.builder(Nullable.class).build()); 48 | } 49 | return annotations; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/ConfigurationAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Factory; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 22 | import io.micronaut.spring.context.aop.SpringConfigurationAdvice; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * Maps {@code @Configuration} to {@link Factory}. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class ConfigurationAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.context.annotation.Configuration"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | List> mappedAnnotations = new ArrayList<>(2); 43 | mappedAnnotations.add(AnnotationValue.builder(Factory.class) 44 | .build()); 45 | 46 | Boolean proxyMethods = annotation.booleanValue("proxyBeanMethods").orElse(true); 47 | if (proxyMethods) { 48 | mappedAnnotations.add(AnnotationValue.builder(SpringConfigurationAdvice.class).build()); 49 | } 50 | return mappedAnnotations; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/FallbackAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Secondary; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.annotation.TypedAnnotationMapper; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | import java.util.List; 23 | import org.springframework.context.annotation.Fallback; 24 | 25 | public class FallbackAnnotationMapper 26 | implements TypedAnnotationMapper { 27 | @Override 28 | public Class annotationType() { 29 | return Fallback.class; 30 | } 31 | 32 | @Override 33 | public List> map(AnnotationValue annotation, VisitorContext visitorContext) { 34 | return List.of(AnnotationValue.builder(Secondary.class).build()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/LazyAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Context; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | /** 28 | * Makes {@code @Lazy(false)} become a {@link Context} scoped bean. 29 | * 30 | * @author graemerocher 31 | * @since 1.0 32 | */ 33 | public class LazyAnnotationMapper extends AbstractSpringAnnotationMapper { 34 | @Override 35 | public String getName() { 36 | return "org.springframework.context.annotation.Lazy"; 37 | } 38 | 39 | @Override 40 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 41 | final boolean lazy = annotation.getValue(Boolean.class).orElse(true); 42 | if (!lazy) { 43 | return Collections.singletonList( 44 | AnnotationValue.builder(Context.class).build() 45 | ); 46 | } 47 | return Collections.emptyList(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/PrimaryAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Primary; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | /** 28 | * Maps {@code @Primary} to {@link Primary}. 29 | * 30 | * @author graemerocher 31 | * @since 1.0 32 | * 33 | */ 34 | public class PrimaryAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.context.annotation.Primary"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | return Collections.singletonList( 43 | AnnotationValue.builder(Primary.class).build() 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/ProfileAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Requires; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | import java.util.Optional; 27 | 28 | /** 29 | * Maps the Spring Profile annotation to {@link Requires}. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class ProfileAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 37 | Optional value = annotation.getValue(String[].class); 38 | return value.>>map(strings -> Collections.singletonList( 39 | AnnotationValue.builder(Requires.class) 40 | .member("env", strings).build() 41 | )).orElse(Collections.emptyList()); 42 | } 43 | 44 | @Override 45 | public String getName() { 46 | return "org.springframework.context.annotation.Profile"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/QualifierAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.core.annotation.AnnotationUtil; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | import java.util.Optional; 27 | 28 | /** 29 | * Maps {@code @Qualifier} to javax.inject.Named. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class QualifierAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.beans.factory.annotation.Qualifier"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | final Optional value = annotation.getValue(String.class); 43 | if (value.isPresent()) { 44 | return Collections.singletonList( 45 | AnnotationValue.builder(AnnotationUtil.NAMED) 46 | .value(value.get()) 47 | .stereotype(AnnotationValue.builder(AnnotationUtil.QUALIFIER).build()) 48 | .build() 49 | ); 50 | } 51 | return Collections.emptyList(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/RepositoryAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | /** 19 | * Maps {@code @Repository} the same was as {@link ComponentAnnotationMapper}. 20 | * 21 | * @author graemerocher 22 | * @since 1.0 23 | */ 24 | public class RepositoryAnnotationMapper extends ComponentAnnotationMapper { 25 | @Override 26 | public String getName() { 27 | return "org.springframework.stereotype.Repository"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/ServiceAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | /** 19 | * Maps {@code @Service} the same was as {@link ComponentAnnotationMapper}. 20 | * 21 | * @author graemerocher 22 | * @since 1.0 23 | */ 24 | public class ServiceAnnotationMapper extends ComponentAnnotationMapper { 25 | @Override 26 | public String getName() { 27 | return "org.springframework.stereotype.Service"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/context/ValueAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Value; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | import java.util.Optional; 27 | 28 | /** 29 | * Maps {@code @Value} to {@link Value}. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class ValueAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.beans.factory.annotation.Value"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | final Optional value = annotation.getValue(String.class); 43 | if (value.isPresent()) { 44 | return Collections.singletonList( 45 | AnnotationValue.builder(Value.class) 46 | .value(value.get()) 47 | .build() 48 | ); 49 | } 50 | return Collections.emptyList(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/event/EventListenerAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.event; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.inject.visitor.VisitorContext; 20 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 21 | 22 | import java.lang.annotation.Annotation; 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | /** 27 | * Maps {@code @EventListener} to {@link io.micronaut.runtime.event.annotation.EventListener}. 28 | * 29 | * @author graemerocher 30 | * @since 1.0 31 | */ 32 | public class EventListenerAnnotationMapper extends AbstractSpringAnnotationMapper { 33 | @Override 34 | public String getName() { 35 | return "org.springframework.context.event.EventListener"; 36 | } 37 | 38 | @Override 39 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 40 | return Collections.singletonList( 41 | AnnotationValue.builder("io.micronaut.runtime.event.annotation.EventListener") 42 | .build() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/scheduling/AsyncAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.scheduling; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.scheduling.annotation.Async; 22 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * Maps {@code @Async} to {@link Async}. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class AsyncAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.scheduling.annotation.Async"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | final AnnotationValueBuilder builder = AnnotationValue.builder(Async.class); 43 | annotation.getValue(String.class).ifPresent(builder::value); 44 | return Collections.singletonList(builder.build()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/tx/TransactionalAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.tx; 17 | 18 | import io.micronaut.aop.InterceptorBinding; 19 | import io.micronaut.aop.InterceptorKind; 20 | import io.micronaut.core.annotation.AnnotationValue; 21 | import io.micronaut.inject.annotation.NamedAnnotationMapper; 22 | import io.micronaut.inject.visitor.VisitorContext; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * Maps {@code @Transactional} to {@code io.micronaut.spring.tx.annotation.Transactional}. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class TransactionalAnnotationMapper implements NamedAnnotationMapper { 35 | 36 | @Override 37 | public String getName() { 38 | return "org.springframework.transaction.annotation.Transactional"; 39 | } 40 | 41 | @Override 42 | public List> map(AnnotationValue annotation, VisitorContext visitorContext) { 43 | return Collections.singletonList( 44 | AnnotationValue.builder(InterceptorBinding.class) 45 | .value(getName()) 46 | .member("kind", InterceptorKind.AROUND) 47 | .build() 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-annotation/src/main/java/io/micronaut/spring/annotation/validation/ValidatedAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.validation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.inject.visitor.VisitorContext; 20 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 21 | import io.micronaut.validation.Validated; 22 | 23 | import java.lang.annotation.Annotation; 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | /** 28 | * Maps {@code @Validated} to {@link Validated}. 29 | * 30 | * @author graemerocher 31 | * @since 1.0 32 | */ 33 | public class ValidatedAnnotationMapper extends AbstractSpringAnnotationMapper { 34 | @Override 35 | public String getName() { 36 | return "org.springframework.validation.annotation.Validated"; 37 | } 38 | 39 | @Override 40 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 41 | return Collections.singletonList( 42 | AnnotationValue.builder(Validated.class).build() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-annotation/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper: -------------------------------------------------------------------------------- 1 | io.micronaut.spring.annotation.context.ProfileAnnotationMapper 2 | io.micronaut.spring.annotation.context.QualifierAnnotationMapper 3 | io.micronaut.spring.annotation.context.BeanAnnotationMapper 4 | io.micronaut.spring.annotation.context.ComponentAnnotationMapper 5 | io.micronaut.spring.annotation.context.FallbackAnnotationMapper 6 | io.micronaut.spring.annotation.context.RepositoryAnnotationMapper 7 | io.micronaut.spring.annotation.context.ServiceAnnotationMapper 8 | io.micronaut.spring.annotation.context.ConfigurationAnnotationMapper 9 | io.micronaut.spring.annotation.context.PrimaryAnnotationMapper 10 | io.micronaut.spring.annotation.validation.ValidatedAnnotationMapper 11 | io.micronaut.spring.annotation.scheduling.ScheduledAnnotationMapper 12 | io.micronaut.spring.annotation.scheduling.AsyncAnnotationMapper 13 | io.micronaut.spring.annotation.event.EventListenerAnnotationMapper 14 | io.micronaut.spring.annotation.context.ValueAnnotationMapper 15 | io.micronaut.spring.annotation.context.AutowiredAnnotationMapper 16 | io.micronaut.spring.annotation.cache.CacheableAnnotationMapper 17 | io.micronaut.spring.annotation.cache.CachePutAnnotationMapper 18 | io.micronaut.spring.annotation.cache.CacheEvictAnnotationMapper 19 | io.micronaut.spring.annotation.tx.TransactionalAnnotationMapper 20 | io.micronaut.spring.annotation.beans.ImportAnnotationMapper 21 | -------------------------------------------------------------------------------- /spring-annotation/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor: -------------------------------------------------------------------------------- 1 | io.micronaut.spring.annotation.beans.ImportAnnotationVisitor 2 | -------------------------------------------------------------------------------- /spring-bom/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "io.micronaut.build.internal.bom" 3 | } 4 | -------------------------------------------------------------------------------- /spring-boot-annotation/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-module' 3 | } 4 | 5 | dependencies { 6 | 7 | api mn.micronaut.core.processor 8 | api mn.micronaut.inject 9 | api mn.micronaut.context 10 | api mn.micronaut.http 11 | 12 | implementation projects.micronautSpringAnnotation 13 | 14 | testAnnotationProcessor mn.micronaut.inject.java 15 | 16 | testImplementation projects.micronautSpringBoot 17 | testImplementation libs.managed.spring.boot 18 | testImplementation libs.spring.boot.autoconfigure 19 | testImplementation libs.spring.boot.actuator 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/ConditionalOnClassAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.core.annotation.NonNull; 19 | 20 | /** 21 | * Maps ConditionalOnClass to Micronaut Requires. 22 | * 23 | * @author graemerocher 24 | * @since 1.0 25 | */ 26 | public class ConditionalOnClassAnnotationMapper extends ConditionalOnBeanAnnotationMapper { 27 | 28 | @Override 29 | public String getName() { 30 | return "org.springframework.boot.autoconfigure.condition.ConditionalOnClass"; 31 | } 32 | 33 | @NonNull 34 | @Override 35 | protected String typesMemberName() { 36 | return "names"; 37 | } 38 | 39 | @NonNull 40 | @Override 41 | protected String requiresMethodName() { 42 | return "classes"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/ConditionalOnMissingBeanAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.core.annotation.NonNull; 19 | 20 | /** 21 | * Maps ConditionalOnMissingBean to Micronaut Requires. 22 | * 23 | * @author graemerocher 24 | * @since 1.0 25 | */ 26 | public class ConditionalOnMissingBeanAnnotationMapper extends ConditionalOnBeanAnnotationMapper { 27 | @Override 28 | public String getName() { 29 | return "org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean"; 30 | } 31 | 32 | @NonNull 33 | @Override 34 | protected String requiresMethodName() { 35 | return "missingBeans"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/ConditionalOnMissingClassAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.core.annotation.NonNull; 19 | 20 | /** 21 | * Maps ConditionalOnMissingClass to Micronaut Requires. 22 | * 23 | * @author graemerocher 24 | * @since 1.0 25 | */ 26 | public class ConditionalOnMissingClassAnnotationMapper extends ConditionalOnClassAnnotationMapper { 27 | 28 | @Override 29 | public String getName() { 30 | return "org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass"; 31 | } 32 | 33 | @NonNull 34 | @Override 35 | protected String requiresMethodName() { 36 | return "missing"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/ConditionalOnNotWebApplicationAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.context.annotation.Requires; 19 | import io.micronaut.core.annotation.AnnotationClassValue; 20 | import io.micronaut.core.annotation.AnnotationValue; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | import io.micronaut.runtime.server.EmbeddedServer; 23 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Maps ConditionalOnNotWebApplication to Micronaut Requires. 31 | * 32 | * @author graemerocher 33 | * @since 1.0 34 | */ 35 | public class ConditionalOnNotWebApplicationAnnotationMapper extends AbstractSpringAnnotationMapper { 36 | @Override 37 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 38 | return Collections.singletonList( 39 | AnnotationValue.builder(Requires.class) 40 | .member("missingBeans", new AnnotationClassValue<>(EmbeddedServer.class)) 41 | .build() 42 | ); 43 | } 44 | 45 | @Override 46 | public String getName() { 47 | return "org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/ConditionalOnWebApplicationAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.context.annotation.Requires; 19 | import io.micronaut.core.annotation.AnnotationClassValue; 20 | import io.micronaut.core.annotation.AnnotationValue; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | import io.micronaut.runtime.server.EmbeddedServer; 23 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Maps ConditionalOnWebApplication to Micronaut Requires. 31 | * 32 | * @author graemerocher 33 | * @since 1.0 34 | */ 35 | public class ConditionalOnWebApplicationAnnotationMapper extends AbstractSpringAnnotationMapper { 36 | @Override 37 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 38 | return Collections.singletonList( 39 | AnnotationValue.builder(Requires.class) 40 | .member("beans", new AnnotationClassValue<>(EmbeddedServer.class)) 41 | .build() 42 | ); 43 | } 44 | 45 | @Override 46 | public String getName() { 47 | return "org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/DeleteOperationAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.core.annotation.NonNull; 19 | 20 | /** 21 | * Maps Actuator DeleteOperation to Micronaut Delete. 22 | * 23 | * @author graemerocher 24 | * @since 1.0 25 | */ 26 | public class DeleteOperationAnnotationMapper extends ReadOperationAnnotationMapper { 27 | @NonNull 28 | @Override 29 | protected String operationName() { 30 | return "Delete"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/SelectorAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.inject.annotation.NamedAnnotationMapper; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | 22 | import java.lang.annotation.Annotation; 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | /** 27 | * Maps Actuator Selector to Micronaut Selector. 28 | * 29 | * @author graemerocher 30 | * @since 1.0 31 | */ 32 | public class SelectorAnnotationMapper implements NamedAnnotationMapper { 33 | @Override 34 | public String getName() { 35 | return "org.springframework.boot.actuate.endpoint.annotation.Selector"; 36 | } 37 | 38 | @Override 39 | public List> map(AnnotationValue annotation, VisitorContext visitorContext) { 40 | return Collections.singletonList( 41 | AnnotationValue.builder("io.micronaut.management.endpoint.annotation.Selector").build() 42 | 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/java/io/micronaut/spring/boot/annotation/WriteOperationAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import io.micronaut.core.annotation.NonNull; 19 | 20 | /** 21 | * Maps Actuator WriteOperation to Micronaut Write. 22 | * 23 | * @author graemerocher 24 | * @since 1.0 25 | */ 26 | public class WriteOperationAnnotationMapper extends ReadOperationAnnotationMapper { 27 | @NonNull 28 | @Override 29 | protected String operationName() { 30 | return "Write"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-annotation/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper: -------------------------------------------------------------------------------- 1 | io.micronaut.spring.boot.annotation.ConfigurationPropertiesAnnotationMapper 2 | io.micronaut.spring.boot.annotation.ConditionalOnMissingBeanAnnotationMapper 3 | io.micronaut.spring.boot.annotation.ConditionalOnBeanAnnotationMapper 4 | io.micronaut.spring.boot.annotation.ConditionalOnPropertyAnnotationMapper 5 | io.micronaut.spring.boot.annotation.ConditionalOnClassAnnotationMapper 6 | io.micronaut.spring.boot.annotation.ConditionalOnMissingClassAnnotationMapper 7 | io.micronaut.spring.boot.annotation.ConditionalOnWebApplicationAnnotationMapper 8 | io.micronaut.spring.boot.annotation.ConditionalOnNotWebApplicationAnnotationMapper 9 | io.micronaut.spring.boot.annotation.ConditionalOnSingleCandidateAnnotationMapper 10 | io.micronaut.spring.boot.annotation.EndpointAnnotationMapper 11 | io.micronaut.spring.boot.annotation.ReadOperationAnnotationMapper 12 | io.micronaut.spring.boot.annotation.WriteOperationAnnotationMapper 13 | io.micronaut.spring.boot.annotation.DeleteOperationAnnotationMapper 14 | io.micronaut.spring.boot.annotation.SelectorAnnotationMapper -------------------------------------------------------------------------------- /spring-boot-starter/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-module' 3 | } 4 | 5 | dependencies { 6 | 7 | api mn.micronaut.aop 8 | api mn.micronaut.inject 9 | api mn.micronaut.context 10 | api libs.managed.spring.boot 11 | 12 | implementation libs.spring.boot.autoconfigure 13 | implementation mn.jakarta.annotation.api 14 | 15 | testAnnotationProcessor mn.micronaut.inject.java 16 | 17 | testCompileOnly mnServlet.servlet.api 18 | 19 | testImplementation mn.micronaut.http 20 | testImplementation libs.spring.boot.autoconfigure 21 | testImplementation libs.spring.boot.actuator 22 | testImplementation libs.spring.boot.test 23 | testImplementation libs.h2database 24 | testImplementation libs.managed.spring.jdbc 25 | 26 | testRuntimeOnly libs.managed.spring.boot.starter.web 27 | testRuntimeOnly libs.spring.boot.starter.tomcat 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-starter/src/main/java/io/micronaut/spring/boot/starter/MicronautBeanFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.starter; 17 | 18 | import io.micronaut.core.annotation.Introspected; 19 | import io.micronaut.core.annotation.NonNull; 20 | import io.micronaut.inject.BeanDefinition; 21 | 22 | /** 23 | * Allows specifying a filter to include or exclude certain beans from being exposed to Spring. 24 | * 25 | * @author graemerocher 26 | * @since 4.3.0 27 | */ 28 | @Introspected 29 | public interface MicronautBeanFilter { 30 | 31 | /** 32 | * Return whether to include the given bean reference as Spring bean. 33 | * @param definition The definition 34 | * @return True if the definition should be exposed as Spring bean 35 | */ 36 | default boolean includes(@NonNull BeanDefinition definition) { 37 | return true; 38 | } 39 | 40 | /** 41 | * Return whether to exclude the given bean definition as Spring bean. 42 | * @param definition The definition 43 | * @return True if the definition should be exposed as Spring bean 44 | */ 45 | default boolean excludes(@NonNull BeanDefinition definition) { 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | io.micronaut.spring.boot.starter.MicronautImportRegistrar 2 | -------------------------------------------------------------------------------- /spring-boot-starter/src/test/java/io/micronaut/spring/boot/autconfigure/AutoConfigureMicronautTest.java: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.boot.autconfigure; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import io.micronaut.context.ApplicationContext; 6 | import io.micronaut.http.codec.MediaTypeCodecRegistry; 7 | import jakarta.inject.Inject; 8 | import jakarta.inject.Singleton; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.autoconfigure.SpringBootApplication; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | 14 | import static org.junit.jupiter.api.Assertions.assertNotNull; 15 | import static org.junit.jupiter.api.Assertions.assertTrue; 16 | 17 | @SpringBootTest(properties = "spring.test.database.replace=any") 18 | public class AutoConfigureMicronautTest { 19 | 20 | @Autowired 21 | DataSource dataSource; 22 | 23 | @Autowired 24 | ReceiveDatasource datasource; 25 | 26 | @Autowired 27 | ApplicationContext context; 28 | 29 | @Autowired 30 | MediaTypeCodecRegistry codecRegistry; 31 | 32 | @Test 33 | void testEnableMicronaut() { 34 | assertNotNull(context); 35 | assertNotNull(codecRegistry); 36 | assertTrue(context.isRunning()); 37 | } 38 | } 39 | 40 | 41 | @SpringBootApplication 42 | class Application { 43 | 44 | } 45 | 46 | @Singleton 47 | class ReceiveDatasource { 48 | @Inject DataSource dataSource; 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-starter/src/test/java/io/micronaut/spring/boot/customautoconfigure/CustomAutoConfigureMicronautTest.java: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.boot.customautoconfigure; 2 | 3 | import java.util.Map; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import io.micronaut.context.ApplicationContext; 8 | import io.micronaut.core.annotation.NonNull; 9 | import io.micronaut.http.codec.MediaTypeCodecRegistry; 10 | import io.micronaut.inject.BeanDefinition; 11 | import io.micronaut.spring.boot.starter.EnableMicronaut; 12 | import io.micronaut.spring.boot.starter.MicronautBeanFilter; 13 | import jakarta.inject.Inject; 14 | import jakarta.inject.Singleton; 15 | import org.junit.jupiter.api.Test; 16 | import org.springframework.beans.factory.ListableBeanFactory; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.boot.autoconfigure.SpringBootApplication; 19 | import org.springframework.boot.test.context.SpringBootTest; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertNotNull; 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | @SpringBootTest 25 | public class CustomAutoConfigureMicronautTest { 26 | @Autowired 27 | CustomReceiveDatasource datasource; 28 | 29 | @Autowired 30 | ApplicationContext context; 31 | 32 | @Autowired 33 | ListableBeanFactory beanFactory; 34 | 35 | @Test 36 | void testEnableMicronaut() { 37 | assertNotNull(context); 38 | assertTrue(context.isRunning()); 39 | Map beansOfType = beanFactory.getBeansOfType(MediaTypeCodecRegistry.class); 40 | assertTrue(beansOfType.isEmpty()); 41 | } 42 | } 43 | 44 | 45 | @SpringBootApplication 46 | @EnableMicronaut(filter = MyFilter.class, exposeToMicronaut = @EnableMicronaut.ExposedBean( 47 | beanType = DataSource.class 48 | )) 49 | class Application { 50 | 51 | } 52 | 53 | class MyFilter implements MicronautBeanFilter { 54 | @Override 55 | public boolean excludes(@NonNull BeanDefinition definition) { 56 | return MediaTypeCodecRegistry.class.isAssignableFrom(definition.getBeanType()); 57 | } 58 | } 59 | @Singleton 60 | class CustomReceiveDatasource { 61 | @Inject 62 | DataSource dataSource; 63 | } 64 | -------------------------------------------------------------------------------- /spring-boot/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.build.internal.spring-module") 3 | } 4 | 5 | dependencies { 6 | 7 | api(projects.micronautSpringContext) 8 | api(libs.managed.spring.boot) 9 | 10 | compileOnly(libs.spring.boot.autoconfigure) 11 | 12 | testAnnotationProcessor(mn.micronaut.inject.java) 13 | testAnnotationProcessor(projects.micronautSpringBootAnnotation) 14 | testAnnotationProcessor(projects.micronautSpringWebAnnotation) 15 | 16 | testCompileOnly(mnServlet.servlet.api) 17 | 18 | testImplementation(projects.micronautSpringWeb) 19 | testImplementation(mn.micronaut.management) 20 | testImplementation(mn.micronaut.http.client) 21 | testImplementation(mn.micronaut.http.server.netty) 22 | testImplementation(libs.spring.boot.autoconfigure) 23 | testImplementation(libs.spring.boot.actuator) 24 | testImplementation(mn.micronaut.jackson.databind) 25 | 26 | testRuntimeOnly(libs.managed.spring.boot.starter.web) 27 | testRuntimeOnly(libs.spring.boot.starter.tomcat) 28 | testRuntimeOnly(mn.jakarta.annotation.api) 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot/src/main/java/io/micronaut/spring/boot/condition/RequiresSingleCandidate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.condition; 17 | 18 | import io.micronaut.context.annotation.Requires; 19 | 20 | import java.lang.annotation.*; 21 | 22 | /** 23 | * A condition class that requires a single candidate. 24 | * 25 | * @author graemerocher 26 | * @since 1.0 27 | */ 28 | @Documented 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD}) 31 | @Requires 32 | public @interface RequiresSingleCandidate { 33 | /** 34 | * The candidate type. 35 | * @return The candidate type 36 | */ 37 | Class value(); 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot/src/main/java/io/micronaut/spring/boot/condition/RequiresSingleCandidateCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.condition; 17 | 18 | import io.micronaut.context.BeanContext; 19 | import io.micronaut.context.condition.Condition; 20 | import io.micronaut.context.condition.ConditionContext; 21 | 22 | /** 23 | * Implementation of {@link RequiresSingleCandidate}. 24 | * 25 | * @author graemerocher 26 | * @since 1.0 27 | */ 28 | public class RequiresSingleCandidateCondition implements Condition { 29 | @Override 30 | public boolean matches(ConditionContext context) { 31 | final Class type = context.getComponent().findAnnotation(RequiresSingleCandidate.class).flatMap(ann -> ann.getValue(Class.class)).orElse(null); 32 | if (type != null) { 33 | final BeanContext beanContext = context.getBeanContext(); 34 | return beanContext.getBeanDefinitions(type).size() == 1; 35 | } 36 | return true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot/src/test/groovy/io/micronaut/spring/boot/EndpointSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot 17 | 18 | import io.micronaut.context.annotation.Property 19 | import io.micronaut.test.extensions.spock.annotation.MicronautTest 20 | import jakarta.inject.Inject 21 | import some.other.pkg.FeaturesClient 22 | import some.other.pkg.FeaturesEndpoint 23 | import spock.lang.Specification 24 | 25 | @MicronautTest 26 | @Property(name = "endpoints.features.sensitive", value = "false") 27 | class EndpointSpec extends Specification { 28 | 29 | @Inject 30 | FeaturesClient client 31 | 32 | void "test endpoint"() { 33 | 34 | when: 35 | def features = client.features() 36 | 37 | then: 38 | features 39 | features.default.enabled 40 | 41 | when: 42 | def status = client.saveFeature("stuff", new FeaturesEndpoint.Feature()) 43 | features = client.features() 44 | 45 | 46 | then: 47 | status 48 | features.size() == 2 49 | features.stuff.enabled == false 50 | client.features("stuff") != null 51 | 52 | when: 53 | client.deleteFeature("stuff") 54 | features = client.features() 55 | 56 | then: 57 | features.size() == 1 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /spring-boot/src/test/groovy/io/micronaut/spring/boot/annotation/ConfigurationPropertiesSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation 17 | 18 | import io.micronaut.context.annotation.Property 19 | import io.micronaut.test.extensions.spock.annotation.MicronautTest 20 | import jakarta.inject.Inject 21 | import spock.lang.Specification 22 | 23 | @MicronautTest 24 | @Property(name='foo.bar.name', value = "myname") 25 | class ConfigurationPropertiesSpec extends Specification { 26 | 27 | @Inject 28 | MyConfigurationProperties myConfigurationProperties 29 | 30 | void "test configuration properties in Micronaut"() { 31 | expect: 32 | myConfigurationProperties.name == 'myname' 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/MyComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Component; 20 | import some.other.pkg.MyOtherComponent; 21 | 22 | @Component 23 | public class MyComponent { 24 | @Autowired 25 | MyOtherComponent myOtherComponent; 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/TestController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.web.bind.annotation.GetMapping; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | import some.other.pkg.FeaturesClient; 23 | 24 | @RestController 25 | @RequestMapping("/spring/test") 26 | public class TestController { 27 | 28 | @Autowired 29 | FeaturesClient featuresClient; 30 | 31 | public TestController() { 32 | System.out.println("Created test controller"); 33 | } 34 | 35 | @GetMapping 36 | public String hello() { 37 | return featuresClient != null ? "good" : "bad"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/MyConfigurationProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation; 17 | 18 | import org.springframework.boot.context.properties.ConfigurationProperties; 19 | 20 | @ConfigurationProperties("foo.bar") 21 | public class MyConfigurationProperties { 22 | 23 | private String name; 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnBeanComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 19 | import org.springframework.stereotype.Component; 20 | 21 | import javax.sql.DataSource; 22 | 23 | @Component 24 | @ConditionalOnBean(DataSource.class) 25 | public class ConditionalOnBeanComponent { 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnBeanComponent2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import io.micronaut.context.env.Environment; 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | @ConditionalOnBean(Environment.class) 24 | public class ConditionalOnBeanComponent2 { 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnClassComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import io.micronaut.spring.boot.annotation.MyConfigurationProperties; 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | @ConditionalOnClass(MyConfigurationProperties.class) 24 | public class ConditionalOnClassComponent { 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnMissingBeanComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 19 | import org.springframework.stereotype.Component; 20 | 21 | import javax.sql.DataSource; 22 | 23 | @Component 24 | @ConditionalOnMissingBean(DataSource.class) 25 | public class ConditionalOnMissingBeanComponent { 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnMissingBeanComponent2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import io.micronaut.spring.boot.annotation.MyConfigurationProperties; 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | @ConditionalOnMissingBean(MyConfigurationProperties.class) 24 | public class ConditionalOnMissingBeanComponent2 { 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnNotWebApplicationComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | @ConditionalOnNotWebApplication 23 | public class ConditionalOnNotWebApplicationComponent { 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnPropertyBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | @ConditionalOnProperty("some.prop") 23 | public class ConditionalOnPropertyBean { 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnPropertyBean2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | @ConditionalOnProperty("some.prop2") 23 | public class ConditionalOnPropertyBean2 { 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnPropertyBean3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | @ConditionalOnProperty(name = "some.prop", havingValue = "something") 23 | public class ConditionalOnPropertyBean3 { 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnPropertyBean4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | @ConditionalOnProperty(prefix = "some", name = "prop3", matchIfMissing = true) 23 | public class ConditionalOnPropertyBean4 { 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnSingleCandidateComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import io.micronaut.spring.boot.annotation.MyConfigurationProperties; 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; 20 | import org.springframework.stereotype.Component; 21 | 22 | @Component 23 | @ConditionalOnSingleCandidate(MyConfigurationProperties.class) 24 | public class ConditionalOnSingleCandidateComponent { 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnSingleCandidateComponent2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import io.micronaut.core.convert.TypeConverter; 19 | import io.micronaut.http.bind.binders.RequestArgumentBinder; 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; 21 | import org.springframework.stereotype.Component; 22 | 23 | @Component 24 | @ConditionalOnSingleCandidate(RequestArgumentBinder.class) 25 | public class ConditionalOnSingleCandidateComponent2 { 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/io/micronaut/spring/boot/annotation/condition/ConditionalOnWebApplicationComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.boot.annotation.condition; 17 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | @ConditionalOnWebApplication 23 | public class ConditionalOnWebApplicationComponent { 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/some/other/pkg/FeaturesClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package some.other.pkg; 17 | 18 | import io.micronaut.http.HttpStatus; 19 | import io.micronaut.http.annotation.Delete; 20 | import io.micronaut.http.annotation.Get; 21 | import io.micronaut.http.annotation.Post; 22 | import io.micronaut.http.client.annotation.Client; 23 | import some.other.pkg.FeaturesEndpoint; 24 | 25 | import java.util.Map; 26 | 27 | @Client("/features") 28 | public interface FeaturesClient { 29 | 30 | 31 | @Get("/") 32 | Map features(); 33 | 34 | @Get("/{name}") 35 | FeaturesEndpoint.Feature features(String name); 36 | 37 | @Delete("/{name}") 38 | HttpStatus deleteFeature(String name); 39 | 40 | @Post("/{name}") 41 | HttpStatus saveFeature(String name, FeaturesEndpoint.Feature feature); 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/some/other/pkg/FeaturesEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package some.other.pkg; 17 | 18 | import org.springframework.boot.actuate.endpoint.annotation.*; 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.util.Map; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | @Component 25 | @Endpoint(id = "features") 26 | public class FeaturesEndpoint { 27 | 28 | private Map features = new ConcurrentHashMap<>(); 29 | 30 | public FeaturesEndpoint() { 31 | final Feature feature = new Feature(); 32 | feature.setEnabled(true); 33 | this.features.put("default", feature); 34 | } 35 | 36 | @ReadOperation 37 | public Map features() { 38 | return features; 39 | } 40 | 41 | @ReadOperation 42 | public Feature feature(@Selector String name) { 43 | return features.get(name); 44 | } 45 | 46 | @WriteOperation 47 | public void configureFeature(@Selector String name, Feature feature) { 48 | features.put(name, feature); 49 | } 50 | 51 | @DeleteOperation 52 | public void deleteFeature(@Selector String name) { 53 | features.remove(name); 54 | } 55 | 56 | public static class Feature { 57 | private boolean enabled; 58 | 59 | public boolean getEnabled() { 60 | return enabled; 61 | } 62 | 63 | public void setEnabled(boolean enabled) { 64 | this.enabled = enabled; 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/some/other/pkg/MyOtherComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package some.other.pkg; 17 | 18 | import org.springframework.stereotype.Component; 19 | 20 | @Component 21 | public class MyOtherComponent { 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot/src/test/java/some/other/pkg/TestClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package some.other.pkg; 17 | 18 | import io.micronaut.http.annotation.Get; 19 | import io.micronaut.http.client.annotation.Client; 20 | 21 | @Client("http://localhost:${spring.test.port}/spring/test") 22 | public interface TestClient { 23 | 24 | @Get("/") 25 | String hello(); 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /spring-context/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-module' 3 | } 4 | 5 | dependencies { 6 | api libs.managed.spring.context 7 | api mn.micronaut.aop 8 | api mn.micronaut.inject 9 | api projects.micronautSpring 10 | 11 | implementation(mnCache.micronaut.cache.core) 12 | 13 | testAnnotationProcessor mn.micronaut.inject.java 14 | testAnnotationProcessor projects.micronautSpringAnnotation 15 | 16 | testImplementation mn.micronaut.jackson.databind 17 | testImplementation mn.micronaut.runtime 18 | testImplementation mn.micronaut.inject.java 19 | testImplementation projects.micronautSpringAnnotation 20 | testImplementation mn.micronaut.inject.java.test 21 | testImplementation libs.managed.spring.jdbc 22 | testImplementation libs.h2database 23 | } 24 | -------------------------------------------------------------------------------- /spring-context/src/main/java/io/micronaut/spring/context/ManagedApplicationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.context; 17 | 18 | import org.springframework.context.ApplicationContext; 19 | import org.springframework.context.Lifecycle; 20 | 21 | import java.io.Closeable; 22 | 23 | /** 24 | * An interface that is more limited in scope than {@link org.springframework.context.ConfigurableApplicationContext} and 25 | * provides lifecycle management. 26 | * 27 | * @author graemerocher 28 | * @since 1.0 29 | */ 30 | public interface ManagedApplicationContext extends ApplicationContext, Lifecycle, Closeable { 31 | } 32 | -------------------------------------------------------------------------------- /spring-context/src/main/java/io/micronaut/spring/context/aop/SpringConfigurationAdvice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.context.aop; 17 | 18 | import io.micronaut.aop.Around; 19 | import io.micronaut.context.annotation.Type; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.Retention; 23 | 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * In order to support the semantics of {@link org.springframework.context.annotation.Configuration} in Spring. This class 28 | * creates a subclass of each {@link org.springframework.context.annotation.Configuration} so that singletons are honoured if 29 | * invoked explicitly. 30 | * 31 | * @see SpringConfigurationInterceptor 32 | * @since 1.0 33 | * @author graemerocher 34 | */ 35 | @SuppressWarnings("WeakerAccess") 36 | @Around 37 | @Type(SpringConfigurationInterceptor.class) 38 | @Documented 39 | @Retention(RUNTIME) 40 | public @interface SpringConfigurationAdvice { 41 | } 42 | -------------------------------------------------------------------------------- /spring-context/src/main/java/io/micronaut/spring/context/event/MicronautApplicationEventPublisher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.context.event; 17 | 18 | import io.micronaut.context.annotation.Primary; 19 | import io.micronaut.core.annotation.Internal; 20 | import io.micronaut.spring.beans.MicronautContextInternal; 21 | import jakarta.inject.Singleton; 22 | import org.springframework.context.ApplicationEvent; 23 | import org.springframework.context.ApplicationEventPublisher; 24 | 25 | /** 26 | * Implementation of the {@link ApplicationEventPublisher} interface for Micronaut. 27 | * 28 | * @author graemerocher 29 | */ 30 | @Singleton 31 | @Primary 32 | @Internal 33 | public class MicronautApplicationEventPublisher implements ApplicationEventPublisher, MicronautContextInternal { 34 | 35 | private final io.micronaut.context.event.ApplicationEventPublisher eventPublisher; 36 | 37 | /** 38 | * Default constructor. 39 | * @param eventPublisher The event publisher to adapt 40 | */ 41 | public MicronautApplicationEventPublisher(io.micronaut.context.event.ApplicationEventPublisher eventPublisher) { 42 | this.eventPublisher = eventPublisher; 43 | } 44 | 45 | @Override 46 | public void publishEvent(ApplicationEvent event) { 47 | eventPublisher.publishEvent(event); 48 | } 49 | 50 | @Override 51 | public void publishEvent(Object event) { 52 | eventPublisher.publishEvent(event); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /spring-context/src/test/groovy/io/micronaut/spring/annotation/context/ConfigurationAnnotationMappingSpec.groovy: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.annotation.context 2 | 3 | import io.micronaut.annotation.processing.test.AbstractTypeElementSpec 4 | import io.micronaut.context.ApplicationContext 5 | import io.micronaut.inject.BeanDefinition 6 | import io.micronaut.spring.context.aop.SpringConfigurationInterceptor 7 | 8 | class ConfigurationAnnotationMappingSpec extends AbstractTypeElementSpec { 9 | 10 | void "test configuration mapping"() { 11 | given: 12 | ApplicationContext applicationContext = buildContext('test.MyConfiguration', ''' 13 | package test; 14 | 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.context.annotation.Primary; 18 | 19 | @Configuration 20 | public class MyConfiguration { 21 | 22 | @Bean 23 | @Primary 24 | public MyBean myBean() { 25 | return new MyBean("default"); 26 | } 27 | 28 | 29 | @Bean("another") 30 | public MyBean anotherBean() { 31 | return new MyBean("another"); 32 | } 33 | } 34 | 35 | class MyBean { 36 | private final String name; 37 | 38 | MyBean(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | } 46 | ''') 47 | 48 | applicationContext.registerSingleton(new SpringConfigurationInterceptor()) 49 | def type = applicationContext.classLoader.loadClass('test.MyBean') 50 | def config = applicationContext.classLoader.loadClass('test.MyConfiguration') 51 | 52 | expect: 53 | applicationContext.getBean(type) == applicationContext.getBean(type) 54 | applicationContext.getBean(config).myBean() == applicationContext.getBean(config).myBean() 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /spring-context/src/test/groovy/io/micronaut/spring/annotation/context/FallbackSpec.groovy: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.annotation.context 2 | 3 | import io.micronaut.context.ApplicationContext 4 | import spock.lang.Specification 5 | 6 | class FallbackSpec extends Specification { 7 | 8 | void "test fallback works"() { 9 | when: 10 | def context = ApplicationContext.run() 11 | 12 | then: 13 | context.getBean(MyInterface) instanceof MyFallback 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-context/src/test/groovy/io/micronaut/spring/annotation/context/MicronautBeanFactoryConfigurationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context 17 | 18 | import com.fasterxml.jackson.databind.ObjectMapper 19 | import io.micronaut.context.ApplicationContext 20 | import io.micronaut.spring.context.MicronautApplicationContext 21 | import org.springframework.beans.factory.NoSuchBeanDefinitionException 22 | import spock.lang.Specification 23 | 24 | class MicronautBeanFactoryConfigurationSpec extends Specification { 25 | 26 | void "test exclude bean types"() { 27 | given: 28 | MicronautApplicationContext applicationContext = new MicronautApplicationContext( 29 | ApplicationContext.builder() 30 | .properties("micronaut.spring.context.bean-excludes": [ObjectMapper]) 31 | ) 32 | applicationContext.start() 33 | 34 | when: 35 | applicationContext.getBean(ObjectMapper) 36 | 37 | then: 38 | thrown(NoSuchBeanDefinitionException) 39 | 40 | and: 41 | !applicationContext.getBeanNamesForType(ObjectMapper) 42 | !applicationContext.getBeansOfType(ObjectMapper) 43 | } 44 | 45 | void "test exclude bean types - no excludes"() { 46 | given: 47 | MicronautApplicationContext applicationContext = new MicronautApplicationContext( 48 | ) 49 | applicationContext.start() 50 | 51 | expect: 52 | applicationContext.getBean(ObjectMapper) 53 | applicationContext.getBeanNamesForType(ObjectMapper) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-context/src/test/groovy/io/micronaut/spring/annotation/context/ParameterizedBeanSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context 17 | 18 | import io.micronaut.context.annotation.Parameter 19 | import io.micronaut.spring.context.MicronautApplicationContext 20 | import jakarta.inject.Singleton 21 | import org.springframework.context.ApplicationContext 22 | import spock.lang.Specification 23 | 24 | class ParameterizedBeanSpec extends Specification { 25 | 26 | void "test that parameterized beans are not exposed as beans to Spring"() { 27 | given: 28 | ApplicationContext ctx = new MicronautApplicationContext() 29 | ctx.start() 30 | 31 | 32 | expect: 33 | !ctx.getBeanNamesForType(MyBean) 34 | 35 | cleanup: 36 | ctx.close() 37 | } 38 | 39 | 40 | @Singleton 41 | static class MyBean { 42 | final String param 43 | 44 | MyBean(@Parameter String param) { 45 | this.param = param 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spring-context/src/test/groovy/io/micronaut/spring/annotation/context/ProfileAnnotationMapperSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context 17 | 18 | import io.micronaut.annotation.processing.test.AbstractTypeElementSpec 19 | import io.micronaut.context.annotation.Requires 20 | import io.micronaut.inject.BeanDefinition 21 | 22 | class ProfileAnnotationMapperSpec extends AbstractTypeElementSpec { 23 | 24 | void "test profile mapping"() { 25 | given: 26 | BeanDefinition definition = buildBeanDefinition( 27 | "test.MyBean", 28 | """ 29 | 30 | package test; 31 | 32 | import org.springframework.context.annotation.*; 33 | import org.springframework.stereotype.Service; 34 | 35 | @Service("myname") 36 | @Profile("test") 37 | class MyBean { 38 | 39 | } 40 | 41 | """ 42 | ) 43 | 44 | expect: 45 | definition.isSingleton() 46 | definition.isAnnotationPresent(Requires) 47 | definition.synthesize(Requires).env() == ['test'] as String[] 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | // tag::class[] 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.Primary; 22 | 23 | @Configuration 24 | public class MyConfiguration { 25 | 26 | @Bean 27 | @Primary 28 | public MyBean myBean() { 29 | return new MyBean("default"); 30 | } 31 | 32 | 33 | @Bean("another") 34 | public MyBean anotherBean() { 35 | return new MyBean("another"); 36 | } 37 | 38 | 39 | public static class MyBean { 40 | private final String name; 41 | 42 | MyBean(String name) { 43 | this.name = name; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | } 50 | } 51 | // end::class[] 52 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyFallback.java: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.annotation.context; 2 | 3 | import org.springframework.context.annotation.Fallback; 4 | 5 | @Fallback 6 | public class MyFallback implements MyInterface { 7 | } 8 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyInterface.java: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.annotation.context; 2 | 3 | public interface MyInterface { 4 | } 5 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyInterfaceImpl.java: -------------------------------------------------------------------------------- 1 | package io.micronaut.spring.annotation.context; 2 | 3 | import io.micronaut.context.annotation.Requires; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | @Requires(property = "activation.property") 8 | public class MyInterfaceImpl implements MyInterface { 9 | } 10 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import org.springframework.scheduling.annotation.Scheduled; 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | public class MyJob { 23 | 24 | private boolean executed; 25 | 26 | @Scheduled(fixedDelay = 100) 27 | void executeMe() { 28 | this.executed = true; 29 | } 30 | 31 | public boolean isExecuted() { 32 | return executed; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyNamedService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import org.springframework.context.event.ContextStartedEvent; 19 | import org.springframework.context.event.EventListener; 20 | import org.springframework.stereotype.Service; 21 | 22 | @Service("myname") 23 | public class MyNamedService { 24 | 25 | 26 | private ContextStartedEvent lastEvent; 27 | 28 | @EventListener 29 | public void onStartup(ContextStartedEvent startedEvent) { 30 | this.lastEvent = startedEvent; 31 | } 32 | 33 | public ContextStartedEvent getLastEvent() { 34 | return lastEvent; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-context/src/test/java/io/micronaut/spring/annotation/context/MyTransactionalService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.annotation.context; 17 | 18 | import io.micronaut.context.annotation.Executable; 19 | import org.springframework.stereotype.Repository; 20 | import org.springframework.transaction.annotation.Isolation; 21 | import org.springframework.transaction.annotation.Propagation; 22 | import org.springframework.transaction.annotation.Transactional; 23 | 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | @Repository 28 | @Transactional( 29 | readOnly = true, 30 | isolation = Isolation.READ_COMMITTED, 31 | propagation = Propagation.REQUIRES_NEW 32 | ) 33 | public class MyTransactionalService { 34 | 35 | @Executable 36 | public List someMethod() { 37 | return Collections.emptyList(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-context/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /spring-web-annotation/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-module' 3 | } 4 | 5 | dependencies { 6 | api projects.micronautSpringAnnotation 7 | api mn.micronaut.core.processor 8 | api mn.micronaut.http 9 | } 10 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/DeleteMappingAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.HttpMethod; 21 | import io.micronaut.http.annotation.Delete; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps Spring DeleteMapping to Micronaut. 27 | * 28 | * @author graemerocher 29 | * @since 1.0 30 | */ 31 | public class DeleteMappingAnnotationTransformer extends RequestMappingAnnotationTransformer { 32 | @Override 33 | public String getName() { 34 | return "org.springframework.web.bind.annotation.DeleteMapping"; 35 | } 36 | 37 | @Override 38 | protected AnnotationValueBuilder newBuilder(HttpMethod httpMethod, AnnotationValue annotation) { 39 | return AnnotationValue.builder(Delete.class); 40 | } 41 | 42 | @Override 43 | protected boolean isHttpMethodMapping(HttpMethod method) { 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/ExceptionHandlerAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationClassValue; 19 | import io.micronaut.core.annotation.AnnotationValue; 20 | import io.micronaut.core.annotation.AnnotationValueBuilder; 21 | import io.micronaut.http.annotation.Error; 22 | import io.micronaut.inject.visitor.VisitorContext; 23 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Maps Spring ExceptionHandler to Micronaut. 31 | * 32 | * @author graemerocher 33 | * @since 1.0 34 | */ 35 | public class ExceptionHandlerAnnotationMapper extends AbstractSpringAnnotationMapper { 36 | @Override 37 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 38 | final AnnotationValueBuilder builder = AnnotationValue.builder(Error.class); 39 | annotation.getValue(AnnotationClassValue.class).ifPresent(annotationClassValue -> builder.member("value", annotationClassValue)); 40 | return Collections.singletonList( 41 | builder 42 | .build() 43 | ); 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return "org.springframework.web.bind.annotation.ExceptionHandler"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/GetMappingAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.HttpMethod; 21 | import io.micronaut.http.annotation.Get; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps Spring GetMapping to Micronaut. 27 | * 28 | * @author graemerocher 29 | * @since 1.0 30 | */ 31 | public class GetMappingAnnotationTransformer extends RequestMappingAnnotationTransformer { 32 | 33 | @Override 34 | public String getName() { 35 | return "org.springframework.web.bind.annotation.GetMapping"; 36 | } 37 | 38 | @Override 39 | protected AnnotationValueBuilder newBuilder(HttpMethod httpMethod, AnnotationValue annotation) { 40 | return AnnotationValue.builder(Get.class); 41 | } 42 | 43 | @Override 44 | protected boolean isHttpMethodMapping(HttpMethod method) { 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/PatchMappingAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.HttpMethod; 21 | import io.micronaut.http.annotation.Patch; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps Spring PatchMapping to Micronaut. 27 | * 28 | * @author graemerocher 29 | * @since 1.0 30 | */ 31 | public class PatchMappingAnnotationTransformer extends RequestMappingAnnotationTransformer { 32 | @Override 33 | public String getName() { 34 | return "org.springframework.web.bind.annotation.PatchMapping"; 35 | } 36 | 37 | @Override 38 | protected AnnotationValueBuilder newBuilder(HttpMethod httpMethod, AnnotationValue annotation) { 39 | return AnnotationValue.builder(Patch.class); 40 | } 41 | 42 | @Override 43 | protected boolean isHttpMethodMapping(HttpMethod method) { 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/PathVariableAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.Nullable; 20 | import io.micronaut.http.annotation.PathVariable; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * Maps Spring RequestMapping to Micronaut. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class PathVariableAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.web.bind.annotation.PathVariable"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | var annotations = new ArrayList>(); 43 | 44 | annotations.add(AnnotationValue.builder(PathVariable.class).member("value", annotation.stringValue().orElse("")).build()); 45 | 46 | var isRequired = annotation.booleanValue("required").orElse(true); 47 | if (!isRequired) { 48 | annotations.add(AnnotationValue.builder(Nullable.class).build()); 49 | } 50 | 51 | return annotations; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/PostMappingAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.HttpMethod; 21 | import io.micronaut.http.annotation.Post; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps Spring PostMapping to Micronaut. 27 | * 28 | * @author graemerocher 29 | * @since 1.0 30 | */ 31 | public class PostMappingAnnotationTransformer extends RequestMappingAnnotationTransformer { 32 | 33 | @Override 34 | public String getName() { 35 | return "org.springframework.web.bind.annotation.PostMapping"; 36 | } 37 | 38 | @Override 39 | protected AnnotationValueBuilder newBuilder(HttpMethod httpMethod, AnnotationValue annotation) { 40 | return AnnotationValue.builder(Post.class); 41 | } 42 | 43 | @Override 44 | protected boolean isHttpMethodMapping(HttpMethod method) { 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/PutMappingAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.HttpMethod; 21 | import io.micronaut.http.annotation.Put; 22 | 23 | import java.lang.annotation.Annotation; 24 | 25 | /** 26 | * Maps Spring PutMapping to Micronaut. 27 | * 28 | * @author graemerocher 29 | * @since 1.0 30 | */ 31 | public class PutMappingAnnotationTransformer extends RequestMappingAnnotationTransformer { 32 | @Override 33 | public String getName() { 34 | return "org.springframework.web.bind.annotation.PutMapping"; 35 | } 36 | 37 | @Override 38 | protected AnnotationValueBuilder newBuilder(HttpMethod httpMethod, AnnotationValue annotation) { 39 | return AnnotationValue.builder(Put.class); 40 | } 41 | 42 | @Override 43 | protected boolean isHttpMethodMapping(HttpMethod method) { 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/RequestBodyAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.Nullable; 20 | import io.micronaut.core.bind.annotation.Bindable; 21 | import io.micronaut.http.annotation.Body; 22 | import io.micronaut.inject.visitor.VisitorContext; 23 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 24 | 25 | import java.lang.annotation.Annotation; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * Maps Spring RequestBody to Micronaut. 31 | * 32 | * @author graemerocher 33 | * @since 1.0 34 | */ 35 | public class RequestBodyAnnotationMapper extends AbstractSpringAnnotationMapper { 36 | @Override 37 | public String getName() { 38 | return "org.springframework.web.bind.annotation.RequestBody"; 39 | } 40 | 41 | @Override 42 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 43 | var mappedAnnotations = new ArrayList>(); 44 | mappedAnnotations.add(AnnotationValue.builder(Body.class).build()); 45 | mappedAnnotations.add(AnnotationValue.builder(Bindable.class).build()); 46 | 47 | var isRequired = annotation.booleanValue("required").orElse(true); 48 | if (!isRequired) { 49 | mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build()); 50 | } 51 | return mappedAnnotations; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/ResponseStatusAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.http.HttpStatus; 20 | import io.micronaut.http.annotation.Status; 21 | import io.micronaut.inject.visitor.VisitorContext; 22 | import io.micronaut.spring.annotation.AbstractSpringAnnotationMapper; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * Maps Spring ResponseStatus to Micronaut. 30 | * 31 | * @author graemerocher 32 | * @since 1.0 33 | */ 34 | public class ResponseStatusAnnotationMapper extends AbstractSpringAnnotationMapper { 35 | @Override 36 | public String getName() { 37 | return "org.springframework.web.bind.annotation.ResponseStatus"; 38 | } 39 | 40 | @Override 41 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 42 | try { 43 | final String code = annotation.stringValue().orElse(annotation.stringValue("code").orElse(null)); 44 | var status = HttpStatus.valueOf(code); 45 | 46 | return Collections.singletonList( 47 | AnnotationValue.builder(Status.class).value(status).build() 48 | ); 49 | } catch (IllegalArgumentException e) { 50 | // ignore 51 | } 52 | return Collections.emptyList(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/RestControllerAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.http.annotation.Controller; 20 | import io.micronaut.inject.visitor.VisitorContext; 21 | import io.micronaut.spring.annotation.context.ComponentAnnotationMapper; 22 | import io.micronaut.validation.Validated; 23 | 24 | import java.lang.annotation.Annotation; 25 | import java.util.List; 26 | 27 | /** 28 | * Maps Spring RestController to Micronaut. 29 | * 30 | * @author graemerocher 31 | * @since 1.0 32 | */ 33 | public class RestControllerAnnotationMapper extends ComponentAnnotationMapper { 34 | @Override 35 | public String getName() { 36 | return "org.springframework.web.bind.annotation.RestController"; 37 | } 38 | 39 | @Override 40 | protected List> mapInternal(AnnotationValue annotation, VisitorContext visitorContext) { 41 | final List> annotationValues = super.mapInternal(annotation, visitorContext); 42 | annotationValues.add(AnnotationValue.builder(Controller.class).build()); 43 | annotationValues.add(AnnotationValue.builder(Validated.class).build()); 44 | return annotationValues; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/exchange/DeleteExchangeAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation.exchange; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.annotation.Delete; 21 | 22 | /** 23 | * Maps Spring DeleteExchange to Micronaut. 24 | * 25 | * @since 5.10.0 26 | */ 27 | public class DeleteExchangeAnnotationTransformer extends HttpExchangeAnnotationTransformer { 28 | 29 | @Override 30 | public String getName() { 31 | return "org.springframework.web.service.annotation.DeleteExchange"; 32 | } 33 | 34 | @Override 35 | protected AnnotationValueBuilder newBuilder(String httpMethod) { 36 | return AnnotationValue.builder(Delete.class); 37 | } 38 | 39 | @Override 40 | protected boolean isHttpMethodMapping(String method) { 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/exchange/GetExchangeAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation.exchange; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.annotation.Get; 21 | 22 | /** 23 | * Maps Spring GetExchange to Micronaut. 24 | * 25 | * @since 5.10.0 26 | */ 27 | public class GetExchangeAnnotationTransformer extends HttpExchangeAnnotationTransformer { 28 | 29 | @Override 30 | public String getName() { 31 | return "org.springframework.web.service.annotation.GetExchange"; 32 | } 33 | 34 | @Override 35 | protected AnnotationValueBuilder newBuilder(String httpMethod) { 36 | return AnnotationValue.builder(Get.class); 37 | } 38 | 39 | @Override 40 | protected boolean isHttpMethodMapping(String method) { 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/exchange/PatchExchangeAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation.exchange; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.annotation.Patch; 21 | 22 | /** 23 | * Maps Spring PatchExchange to Micronaut. 24 | * 25 | * @since 5.10.0 26 | */ 27 | public class PatchExchangeAnnotationTransformer extends HttpExchangeAnnotationTransformer { 28 | 29 | @Override 30 | public String getName() { 31 | return "org.springframework.web.service.annotation.PatchExchange"; 32 | } 33 | 34 | @Override 35 | protected AnnotationValueBuilder newBuilder(String httpMethod) { 36 | return AnnotationValue.builder(Patch.class); 37 | } 38 | 39 | @Override 40 | protected boolean isHttpMethodMapping(String method) { 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/exchange/PostExchangeAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation.exchange; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.annotation.Post; 21 | 22 | /** 23 | * Maps Spring PostExchange to Micronaut. 24 | * 25 | * @since 5.10.0 26 | */ 27 | public class PostExchangeAnnotationTransformer extends HttpExchangeAnnotationTransformer { 28 | 29 | @Override 30 | public String getName() { 31 | return "org.springframework.web.service.annotation.PostExchange"; 32 | } 33 | 34 | @Override 35 | protected AnnotationValueBuilder newBuilder(String httpMethod) { 36 | return AnnotationValue.builder(Post.class); 37 | } 38 | 39 | @Override 40 | protected boolean isHttpMethodMapping(String method) { 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/java/io/micronaut/spring/web/annotation/exchange/PutExchangeAnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation.exchange; 17 | 18 | import io.micronaut.core.annotation.AnnotationValue; 19 | import io.micronaut.core.annotation.AnnotationValueBuilder; 20 | import io.micronaut.http.annotation.Put; 21 | 22 | /** 23 | * Maps Spring PutExchange to Micronaut. 24 | * 25 | * @since 5.10.0 26 | */ 27 | public class PutExchangeAnnotationTransformer extends HttpExchangeAnnotationTransformer { 28 | 29 | @Override 30 | public String getName() { 31 | return "org.springframework.web.service.annotation.PutExchange"; 32 | } 33 | 34 | @Override 35 | protected AnnotationValueBuilder newBuilder(String httpMethod) { 36 | return AnnotationValue.builder(Put.class); 37 | } 38 | 39 | @Override 40 | protected boolean isHttpMethodMapping(String method) { 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper: -------------------------------------------------------------------------------- 1 | io.micronaut.spring.web.annotation.RequestBodyAnnotationMapper 2 | io.micronaut.spring.web.annotation.RequestParamAnnotationMapper 3 | io.micronaut.spring.web.annotation.RequestPartAnnotationMapper 4 | io.micronaut.spring.web.annotation.RequestHeaderAnnotationMapper 5 | io.micronaut.spring.web.annotation.PathVariableAnnotationMapper 6 | io.micronaut.spring.web.annotation.CookieValueAnnotationMapper 7 | io.micronaut.spring.web.annotation.RequestAttributeAnnotationMapper 8 | io.micronaut.spring.web.annotation.ResponseStatusAnnotationMapper 9 | io.micronaut.spring.web.annotation.RestControllerAnnotationMapper 10 | io.micronaut.spring.web.annotation.ExceptionHandlerAnnotationMapper 11 | -------------------------------------------------------------------------------- /spring-web-annotation/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationTransformer: -------------------------------------------------------------------------------- 1 | io.micronaut.spring.web.annotation.RequestMappingAnnotationTransformer 2 | io.micronaut.spring.web.annotation.PutMappingAnnotationTransformer 3 | io.micronaut.spring.web.annotation.PostMappingAnnotationTransformer 4 | io.micronaut.spring.web.annotation.PatchMappingAnnotationTransformer 5 | io.micronaut.spring.web.annotation.DeleteMappingAnnotationTransformer 6 | io.micronaut.spring.web.annotation.GetMappingAnnotationTransformer 7 | io.micronaut.spring.web.annotation.exchange.HttpExchangeAnnotationTransformer 8 | io.micronaut.spring.web.annotation.exchange.PutExchangeAnnotationTransformer 9 | io.micronaut.spring.web.annotation.exchange.PostExchangeAnnotationTransformer 10 | io.micronaut.spring.web.annotation.exchange.PatchExchangeAnnotationTransformer 11 | io.micronaut.spring.web.annotation.exchange.DeleteExchangeAnnotationTransformer 12 | io.micronaut.spring.web.annotation.exchange.GetExchangeAnnotationTransformer 13 | -------------------------------------------------------------------------------- /spring-web/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.micronaut.build.internal.spring-module' 3 | } 4 | 5 | dependencies { 6 | api platform(libs.boms.spring) 7 | api projects.micronautSpringContext 8 | api libs.spring.web 9 | api mn.reactor 10 | 11 | implementation mn.micronaut.http 12 | 13 | compileOnly mn.micronaut.http.server.netty 14 | compileOnly(mnViews.micronaut.views.core) 15 | 16 | testAnnotationProcessor mn.micronaut.inject.java 17 | testAnnotationProcessor projects.micronautSpringAnnotation 18 | testAnnotationProcessor projects.micronautSpringWebAnnotation 19 | 20 | testImplementation mn.micronaut.inject.java 21 | testImplementation mnValidation.micronaut.validation 22 | testImplementation mn.micronaut.jackson.databind 23 | testImplementation mn.micronaut.http.client 24 | testImplementation mn.micronaut.http.server.netty 25 | 26 | testRuntimeOnly(mnViews.micronaut.views.thymeleaf) 27 | testRuntimeOnly libs.spring.boot.starter.thymeleaf 28 | } 29 | -------------------------------------------------------------------------------- /spring-web/src/main/java/io/micronaut/spring/web/bind/HttpMethodArgumentBinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.bind; 17 | 18 | import io.micronaut.core.convert.ArgumentConversionContext; 19 | import io.micronaut.core.type.Argument; 20 | import io.micronaut.http.HttpRequest; 21 | import io.micronaut.http.bind.binders.TypedRequestArgumentBinder; 22 | import jakarta.inject.Singleton; 23 | import org.springframework.http.HttpMethod; 24 | 25 | import java.util.Optional; 26 | 27 | /** 28 | * Adds ability to bind {@link HttpMethod}. 29 | * 30 | * @author graemerocher 31 | * @since 1.0 32 | */ 33 | @Singleton 34 | public class HttpMethodArgumentBinder implements TypedRequestArgumentBinder { 35 | @Override 36 | public Argument argumentType() { 37 | return Argument.of(HttpMethod.class); 38 | } 39 | 40 | @Override 41 | public BindingResult bind(ArgumentConversionContext context, HttpRequest source) { 42 | return () -> Optional.of(HttpMethod.valueOf(source.getMethod().name())); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-web/src/main/java/io/micronaut/spring/web/bind/ModelMapRequestArgumentBinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.bind; 17 | 18 | import io.micronaut.core.convert.ArgumentConversionContext; 19 | import io.micronaut.core.type.Argument; 20 | import io.micronaut.http.HttpRequest; 21 | import io.micronaut.http.bind.binders.TypedRequestArgumentBinder; 22 | import org.springframework.ui.ModelMap; 23 | 24 | import java.util.Optional; 25 | 26 | /** 27 | * Binds the {@link ModelMap} type. 28 | * 29 | * @author graemerocher 30 | * @since 1.0 31 | */ 32 | public class ModelMapRequestArgumentBinder implements TypedRequestArgumentBinder { 33 | 34 | /** 35 | * The name of the request attribute to use. 36 | */ 37 | public static final String ATTRIBUTE = "io.micronaut.spring.MODEL_MAP"; 38 | 39 | @Override 40 | public Argument argumentType() { 41 | return Argument.of(ModelMap.class); 42 | } 43 | 44 | @Override 45 | public BindingResult bind(ArgumentConversionContext context, HttpRequest source) { 46 | final Optional attribute = source.getAttribute(ATTRIBUTE, ModelMap.class); 47 | if (!attribute.isPresent()) { 48 | final ModelMap modelMap = new ModelMap(); 49 | source.setAttribute(ATTRIBUTE, modelMap); 50 | return () -> Optional.of(modelMap); 51 | } 52 | return () -> attribute; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /spring-web/src/main/java/io/micronaut/spring/web/reactive/ChannelResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.reactive; 17 | 18 | import io.micronaut.http.HttpRequest; 19 | import io.micronaut.http.server.netty.HttpContentProcessor; 20 | import io.netty.channel.Channel; 21 | 22 | import java.util.Optional; 23 | 24 | /** 25 | * Channel resolver interface. 26 | * 27 | * @author graemerocher 28 | * @since 1.0 29 | */ 30 | public interface ChannelResolver { 31 | 32 | /** 33 | * Resolve the backing netty channel. 34 | * @param request The request 35 | * @return The channel 36 | */ 37 | Optional resolveChannel(HttpRequest request); 38 | 39 | /** 40 | * Resolve the content processor. 41 | * @param request The request 42 | * @return The processor 43 | */ 44 | Optional resolveContentProcessor(HttpRequest request); 45 | } 46 | -------------------------------------------------------------------------------- /spring-web/src/main/java/io/micronaut/spring/web/reactive/DefaultChannelResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.reactive; 17 | 18 | import io.micronaut.http.HttpRequest; 19 | import io.micronaut.http.server.netty.HttpContentProcessor; 20 | import io.netty.channel.Channel; 21 | import jakarta.inject.Singleton; 22 | 23 | import java.util.Optional; 24 | 25 | /** 26 | * Default implementation of {@link ChannelResolver}. 27 | * 28 | * @author graemerocher 29 | * @since 1.0 30 | */ 31 | @Singleton 32 | public class DefaultChannelResolver implements ChannelResolver { 33 | @Override 34 | public Optional resolveChannel(HttpRequest request) { 35 | return Optional.empty(); 36 | } 37 | 38 | @Override 39 | public Optional resolveContentProcessor(HttpRequest request) { 40 | return Optional.empty(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-web/src/test/java/io/micronaut/spring/web/annotation/Greeting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import com.fasterxml.jackson.annotation.JsonCreator; 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | 21 | public class Greeting { 22 | 23 | private final long id; 24 | private final String content; 25 | 26 | @JsonCreator 27 | public Greeting(@JsonProperty("id") long id, @JsonProperty("content") String content) { 28 | this.id = id; 29 | this.content = content; 30 | } 31 | 32 | public long getId() { 33 | return id; 34 | } 35 | 36 | public String getContent() { 37 | return content; 38 | } 39 | } -------------------------------------------------------------------------------- /spring-web/src/test/java/io/micronaut/spring/web/annotation/NestedGreetingController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation; 17 | 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.bind.annotation.RequestParam; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import java.util.concurrent.atomic.AtomicLong; 23 | 24 | @RestController 25 | @RequestMapping("/nested") 26 | public class NestedGreetingController { 27 | 28 | private static final String TEMPLATE = "Hello Nested, %s!"; 29 | 30 | private final AtomicLong counter = new AtomicLong(); 31 | 32 | @RequestMapping("/greeting") 33 | public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { 34 | return new Greeting(counter.incrementAndGet(), 35 | String.format(TEMPLATE, name)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-web/src/test/java/io/micronaut/spring/web/annotation/exchange/ExchangeGreetingClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.web.annotation.exchange; 17 | 18 | import io.micronaut.http.annotation.Header; 19 | import io.micronaut.http.client.annotation.Client; 20 | import io.micronaut.spring.web.annotation.Greeting; 21 | import org.springframework.web.bind.annotation.RequestBody; 22 | import org.springframework.web.service.annotation.PostExchange; 23 | 24 | @Client("/exchange") 25 | public interface ExchangeGreetingClient extends ExchangeGreetingApi { 26 | 27 | @PostExchange("/request") 28 | @Header(name = "Foo", value = "Bar") 29 | Greeting requestTest(@RequestBody Greeting greeting); 30 | } 31 | -------------------------------------------------------------------------------- /spring-web/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /spring-web/src/test/resources/views/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Home 4 | 5 | 6 |
7 |

8 |
9 | 10 | -------------------------------------------------------------------------------- /spring/README.md: -------------------------------------------------------------------------------- 1 | # Micronaut Spring 2 | 3 | Various adapter classes for using Spring APIs within micronaut. -------------------------------------------------------------------------------- /spring/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.build.internal.spring-module") 3 | } 4 | dependencies { 5 | 6 | compileOnly(libs.managed.spring.jdbc) 7 | compileOnly(mnTest.micronaut.test.core) 8 | 9 | api(libs.managed.spring) 10 | api(libs.managed.spring.tx) 11 | api(libs.managed.spring.context) 12 | api(mn.micronaut.inject) 13 | api(mn.micronaut.aop) 14 | 15 | implementation(mn.micronaut.core.processor) 16 | 17 | testAnnotationProcessor(mn.micronaut.inject.java) 18 | 19 | testCompileOnly(mn.micronaut.inject.groovy) 20 | 21 | testImplementation(libs.spock.spring) 22 | testImplementation(libs.spring.test) 23 | } 24 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/beans/ImportedBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.beans; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Meta-annotation used on other types to describe the type that imported this type. 25 | * 26 | * @author graemerocher 27 | * @see SpringImport 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ElementType.TYPE, ElementType.METHOD}) 31 | public @interface ImportedBy { 32 | /** 33 | * @return The type that imported this bean. 34 | */ 35 | Class value(); 36 | } 37 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/beans/MicronautContextInternal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.beans; 17 | 18 | /** 19 | * Marker interface for internal components. 20 | * @author graemerocher 21 | * @since 4.3.0 22 | */ 23 | public interface MicronautContextInternal { 24 | } 25 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/beans/SpringImport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.beans; 17 | 18 | import java.lang.annotation.Repeatable; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | 22 | import io.micronaut.core.annotation.Internal; 23 | 24 | /** 25 | * Allows the spring import annotation to be represented as a repeated annotation. 26 | * This is an internal annotation and should not be used directly. 27 | * 28 | * @author graemerocher 29 | * @since 4.3.0 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Repeatable(SpringImport.List.class) 33 | @Internal 34 | public @interface SpringImport { 35 | /** 36 | * The type to import. 37 | * @return The type to import 38 | */ 39 | Class value(); 40 | 41 | /** 42 | * Repeatable wrapper type. 43 | */ 44 | @Retention(RetentionPolicy.RUNTIME) 45 | @interface List { 46 | SpringImport[] value(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/beans/aware/ImportAwareListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.beans.aware; 17 | 18 | import io.micronaut.context.event.BeanCreatedEvent; 19 | import io.micronaut.context.event.BeanCreatedEventListener; 20 | import io.micronaut.core.annotation.Internal; 21 | import io.micronaut.inject.BeanDefinition; 22 | import io.micronaut.spring.beans.ImportedBy; 23 | import io.micronaut.spring.core.type.BeanDefinitionSpringMetadata; 24 | import jakarta.inject.Singleton; 25 | import org.springframework.context.annotation.ImportAware; 26 | 27 | /** 28 | * Handles the import aware interface. 29 | * @author graemerocher 30 | * @since 4.3.0 31 | */ 32 | @Singleton 33 | @Internal 34 | public class ImportAwareListener implements BeanCreatedEventListener { 35 | @Override 36 | public ImportAware onCreated(BeanCreatedEvent event) { 37 | ImportAware importAware = event.getBean(); 38 | BeanDefinition beanDefinition = event.getBeanDefinition(); 39 | Class importedBy = beanDefinition.getAnnotationMetadata().classValue(ImportedBy.class).orElse(null); 40 | if (importedBy != null) { 41 | event.getSource().findBeanDefinition(importedBy).ifPresent(importedDef -> 42 | importAware.setImportMetadata(new BeanDefinitionSpringMetadata(importedDef)) 43 | ); 44 | } 45 | return importAware; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/beans/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Classes to integrate Micronaut with Spring. 18 | * 19 | * @author graemerocher 20 | * @since 1.0 21 | */ 22 | package io.micronaut.spring.beans; 23 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/core/env/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Spring property resolver adapter. 18 | * 19 | * @author Graeme Rocher 20 | * @since 1.0 21 | */ 22 | package io.micronaut.spring.core.env; 23 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/core/event/ApplicationEventPublisherAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.core.event; 17 | 18 | import org.springframework.context.ApplicationEvent; 19 | import org.springframework.context.ApplicationEventPublisher; 20 | 21 | /** 22 | * An adapter for Spring's {@link ApplicationEventPublisher} interface. 23 | * 24 | * @author graemerocher 25 | * @since 1.0 26 | */ 27 | public class ApplicationEventPublisherAdapter implements ApplicationEventPublisher { 28 | 29 | private final io.micronaut.context.event.ApplicationEventPublisher eventPublisher; 30 | 31 | /** 32 | * Constructor. 33 | * 34 | * @param eventPublisher The application event publisher 35 | */ 36 | public ApplicationEventPublisherAdapter(io.micronaut.context.event.ApplicationEventPublisher eventPublisher) { 37 | if (eventPublisher == null) { 38 | throw new IllegalArgumentException("Event publisher must be specified"); 39 | } 40 | this.eventPublisher = eventPublisher; 41 | } 42 | 43 | @Override 44 | public void publishEvent(ApplicationEvent event) { 45 | this.eventPublisher.publishEvent(event); 46 | } 47 | 48 | @Override 49 | public void publishEvent(Object event) { 50 | this.eventPublisher.publishEvent(event); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/core/event/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Spring adapter for event publishing. 18 | * 19 | * @author Graeme Rocher 20 | * @since 1.0 21 | */ 22 | package io.micronaut.spring.core.event; 23 | -------------------------------------------------------------------------------- /spring/src/main/java/io/micronaut/spring/tx/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * Spring transactional annotations. 18 | * 19 | * @author Graeme Rocher 20 | * @since 1.0 21 | */ 22 | package io.micronaut.spring.tx.annotation; 23 | -------------------------------------------------------------------------------- /spring/src/main/resources/META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference/io.micronaut.spring.beans.ObjectProviderBeanDefinition: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/micronaut-projects/micronaut-spring/9ef83225e81d4def76607327886d98488a465734/spring/src/main/resources/META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference/io.micronaut.spring.beans.ObjectProviderBeanDefinition -------------------------------------------------------------------------------- /spring/src/test/groovy/io/micronaut/spring/beans/MicronautBeanProcessorByConcreteTypeSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.beans 17 | 18 | import jakarta.inject.Singleton 19 | import org.springframework.beans.factory.annotation.Autowired 20 | import org.springframework.context.ApplicationContext 21 | import org.springframework.context.annotation.Bean 22 | import org.springframework.context.annotation.Configuration 23 | import org.springframework.test.context.ContextConfiguration 24 | import spock.lang.Specification 25 | 26 | @ContextConfiguration(classes = [ByConcreteTypeConfig]) 27 | class MicronautBeanProcessorByConcreteTypeSpec extends Specification { 28 | 29 | @Autowired 30 | ApplicationContext applicationContext 31 | 32 | void 'test widget bean'() { 33 | expect: 34 | applicationContext.getBean(Widget) instanceof Widget 35 | } 36 | } 37 | 38 | @Configuration 39 | class ByConcreteTypeConfig { 40 | 41 | @Bean 42 | MicronautBeanProcessor widgetProcessor() { 43 | new MicronautBeanProcessor(Widget) 44 | } 45 | } 46 | 47 | @Singleton 48 | class Widget {} 49 | -------------------------------------------------------------------------------- /spring/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/docs/guide/introduction.adoc: -------------------------------------------------------------------------------- 1 | Micronaut uses Ahead of Time (AOT) compilation to pre-compute your applications requirements at compile time. The result of this is significantly lower memory requirements, faster startup time, and reflection free framework infrastructure. 2 | 3 | This project consists of various components that make it easier to: 4 | 5 | * Integrate Spring components into a Micronaut application 6 | * Run Spring applications as Micronaut applications 7 | * Expose Micronaut Beans to a Spring Application 8 | 9 | To achieve this the project provides the ability to use a subset of the Spring Annotation-Based programming model to build Micronaut applications. The goal is not necessarily to provide an alternative runtime for Spring, but instead to enable the ability to build libraries that work with both Spring and Micronaut. -------------------------------------------------------------------------------- /src/main/docs/guide/micronautInsideSpring.adoc: -------------------------------------------------------------------------------- 1 | It may be desirable to use Micronaut modules or libraries from a Spring or Spring Boot application. For example, you may wish to use the https://guides.micronaut.io/latest/micronaut-http-client.html[Micronaut HTTP Client] or https://micronaut-projects.github.io/micronaut-data/latest/guide/[Micronaut Data] within your Spring application. There are several ways you can integrate Micronaut into a Spring application which are described below. 2 | -------------------------------------------------------------------------------- /src/main/docs/guide/micronautInsideSpring/beanPostProcessor.adoc: -------------------------------------------------------------------------------- 1 | The link:{micronautspringapi}/io/micronaut/spring/beans/MicronautBeanProcessor.html[MicronautBeanProcessor] 2 | class is a `BeanFactoryPostProcessor` which will add Micronaut beans to a 3 | Spring Application Context. An instance of `MicronautBeanProcessor` should 4 | be added to the Spring Application Context. `MicronautBeanProcessor` requires 5 | a constructor parameter which represents a list of the types of 6 | Micronaut beans which should be added to the Spring Application Context. The 7 | processor may be used in any Spring application. As an example, a Grails 3 8 | application could take advantage of `MicronautBeanProcessor` to add all the 9 | Micronaut HTTP Client beans to the Spring Application Context with something 10 | like the folowing: 11 | 12 | [source,groovy] 13 | ---- 14 | // grails-app/conf/spring/resources.groovy 15 | import io.micronaut.spring.beans.MicronautBeanProcessor 16 | import io.micronaut.http.client.annotation.Client 17 | 18 | beans = { 19 | httpClientBeanProcessor MicronautBeanProcessor, Client 20 | } 21 | ---- 22 | 23 | Multiple types may be specified: 24 | 25 | [source,groovy] 26 | ---- 27 | // grails-app/conf/spring/resources.groovy 28 | import io.micronaut.spring.beans.MicronautBeanProcessor 29 | import io.micronaut.http.client.annotation.Client 30 | import com.sample.Widget 31 | 32 | beans = { 33 | httpClientBeanProcessor MicronautBeanProcessor, [Client, Widget] 34 | } 35 | ---- 36 | 37 | In a non-Grails application something similar may be specified using 38 | any of Spring's bean definition styles: 39 | 40 | [source, groovy] 41 | ---- 42 | include::spring/src/test/groovy/io/micronaut/spring/beans/MicronautBeanProcessorByAnnotationTypeSpec.groovy[tags=springconfig, indent=0] 43 | ---- 44 | -------------------------------------------------------------------------------- /src/main/docs/guide/micronautInsideSpring/springParentContext.adoc: -------------------------------------------------------------------------------- 1 | You can also use Micronaut for Spring as the parent application context to a regular Spring application. 2 | 3 | This has a number of benefits, you can for example define beans using Micronaut and consume any Micronaut beans into a Spring application, resulting in Spring using less memory and having reflection free infrastructure. 4 | 5 | You can also use any Micronaut feature from a regular Spring Boot or Spring application including the https://docs.micronaut.io/latest/guide/index.html#clientAnnotation[declaring clients for HTTP] and https://docs.micronaut.io/latest/guide/index.html#kafkaClient[Kafka]. 6 | 7 | You can also use any compilation time tools from Micronaut with Spring such as Micronaut's support for https://docs.micronaut.io/latest/guide/index.html#openapi[Swagger]. 8 | 9 | The following example shows how to Configure your Spring Boot application with a Micronaut powered parent application context using `SpringApplicationBuilder`: 10 | 11 | .Using the Micronaut Parent Context 12 | [source,java] 13 | ---- 14 | var builder = new SpringApplicationBuilder(); 15 | var context = new MicronautApplicationContext(); 16 | context.start(); 17 | builder.parent(context) 18 | .sources(Application.class) 19 | .build() 20 | .run(); 21 | ---- 22 | -------------------------------------------------------------------------------- /src/main/docs/guide/releaseHistory.adoc: -------------------------------------------------------------------------------- 1 | For this project, you can find a list of releases (with release notes) here: 2 | 3 | https://github.com/{githubSlug}/releases[https://github.com/{githubSlug}/releases] 4 | -------------------------------------------------------------------------------- /src/main/docs/guide/repository.adoc: -------------------------------------------------------------------------------- 1 | You can find the source code of this project in this repository: 2 | 3 | https://github.com/{githubSlug}[https://github.com/{githubSlug}] -------------------------------------------------------------------------------- /src/main/docs/guide/sharingLibraries.adoc: -------------------------------------------------------------------------------- 1 | If you have a lot of existing Spring applications it may be useful to share libraries between Micronaut and Spring. 2 | 3 | This is a common requirement if you want to say share common injectable components that can be added to classpath. 4 | 5 | If you have this use case you can resolve it by using Spring annotations to define the components using annotations like link:{springapi}org/springframework/context/annotation/Configuration.html[@configuration], link:{springapi}org/springframework/stereotype/Component.html[@component] and link:{springapi}org/springframework/context/annotation/Bean.html[@bean]. 6 | 7 | For example: 8 | 9 | .Example Spring Configuration 10 | [source, java] 11 | ---- 12 | include::spring-context/src/test/java/io/micronaut/spring/annotation/context/MyConfiguration.java[tags=class, indent=0] 13 | ---- 14 | 15 | The above configuration, which exposes a bean of type `MyBean`, can be imported and used by any Spring application using the link:{springapi}org/springframework/context/annotation/Import.html[@import] annotation declared as follows: 16 | 17 | .Using `@Import` 18 | [source, java] 19 | ---- 20 | import org.springframework.context.annotation.Import; 21 | 22 | @Import(MyConfiguration.class) 23 | class Application {} 24 | ---- 25 | 26 | You can additionally use the same configuration in a Micronaut application by use the same declaration as above assuming you have correctly configured Micronaut for Spring. See the example project that is part of the guide https://guides.micronaut.io/latest/micronaut-spring-boot.html[Run a Spring Boot Application as a Micronaut Application] for how to configure Micronaut for Spring. 27 | 28 | Micronaut will import all declared beans at compilation time. The only limitation is that `ImportBeanDefinitionRegistrar` that require runtime interfaces like `BeanClassLoaderAware` will fail to import with a compilation error since import processing happens during compilation with Micronaut. When creating shared components try to avoid defining `ImportBeanDefinitionRegistrar` types that depend on one of the following interfaces: 29 | 30 | * `BeanClassLoaderAware` 31 | * `BeanFactoryAware` 32 | * `EnvironmentAware` 33 | * `ResourceLoaderAware` 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/docs/guide/springGuides.adoc: -------------------------------------------------------------------------------- 1 | See the following list of guides to learn more about working with Spring in the Micronaut Framework: 2 | 3 | https://guides.micronaut.io/latest/tag-spring-boot.html 4 | -------------------------------------------------------------------------------- /src/main/docs/guide/springToMicronaut.adoc: -------------------------------------------------------------------------------- 1 | Micronaut for Spring allows you to use traditional Spring annotations which are mapped to Micronaut annotations at compilation time. This allows you to write an application that can be imported to another Spring or Micronaut application without change. 2 | 3 | Unlike traditional runtime reflection based frameworks Micronaut uses Ahead of Time (AOT) compilation, hence there is no runtime overhead to supporting an additional set of annotations (in this case Spring's annotation programming model). 4 | 5 | As part of this project an https://guides.micronaut.io/latest/micronaut-spring-boot.html[Example Application] is provided that includes no dependencies on Micronaut itself in the source code (only Spring dependencies) but is computed into a Micronaut application at compilation time. 6 | 7 | The value in this as follows: 8 | 9 | * You can take the compiled application and include it into another Spring or Micronaut application without change, which is a huge win for library authors. 10 | * If you have an existing team of Spring developers they can be up and running with Micronaut without learning a new annotation DSL. 11 | * Existing tooling like IntelliJ IDEA and STS 4.0 "Just Work" with Micronaut 12 | 13 | In addition, the guide for https://guides.micronaut.io/latest/spring-boot-to-micronaut-application-class.html[Application Class - Spring Boot to Micronaut Framework] compares the application class of a Spring Boot application to that of a Micronaut Framework application. 14 | 15 | Note that Spring is huge and only a subset of Spring is supported, but enough to build real applications and libraries that work with either Micronaut or Spring. The following documentation covers the annotations and Spring interfaces that are supported. 16 | 17 | NOTE: If an annotation or interface of Spring is not mentioned in this documentation consider it unsupported. 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/docs/guide/springToMicronaut/micronautClient.adoc: -------------------------------------------------------------------------------- 1 | Since annotations values are mapped at compilation time, this also impacts the authoring of Micronaut's compile-time declarative HTTP client. 2 | 3 | You can essentially use Spring annotations to a defined a compilation-time HTTP client: 4 | 5 | .Spring `@Client` Implementation 6 | [source,java] 7 | ---- 8 | include::spring-web/src/test/java/io/micronaut/spring/web/annotation/GreetingClient.java[] 9 | ---- 10 | 11 | This also means you can define a common interface between client and server of a Spring application and compute the client at compilation name. 12 | 13 | TIP: if you are using low-level HTTP clients see the guide for https://guides.micronaut.io/latest/spring-boot-to-micronaut-uri-components-builder-vs-uri-builder.html[Building URIs - Spring Boot to Micronaut Framework] that compares Spring's `UriComponentsBuilder` to Micronaut Framework's `UriBuilder`. 14 | -------------------------------------------------------------------------------- /src/main/docs/guide/springToMicronaut/springEvents.adoc: -------------------------------------------------------------------------------- 1 | For compatibility the following `ApplicationEvent` instances are supported: 2 | 3 | .Supported Spring Events 4 | |=== 5 | 6 | |Spring Event|Description 7 | 8 | |link:{springapi}org/springframework/context/event/ContextStartedEvent.html[ContextStartedEvent] 9 | |Fired when the application context is started 10 | 11 | |link:{springapi}org/springframework/context/event/ContextClosedEvent.html[ContextClosedEvent] 12 | |Fired when the application context is shut down 13 | |=== 14 | 15 | You can write methods annotated with link:{springapi}org/springframework/context/event/EventListener.html[@EventListener] to receive the events in either framework. 16 | -------------------------------------------------------------------------------- /src/main/docs/guide/springToMicronaut/springInterfaces.adoc: -------------------------------------------------------------------------------- 1 | The following Spring interfaces are supported and can be injected into any bean: 2 | 3 | .Supported Injectable Interfaces 4 | |=== 5 | 6 | |Spring Interface|Adapted Target|Description 7 | |link:{springapi}org/springframework/core/env/Environment.html[Environment] 8 | |link:{micronautapi}context/env/Environment.html[Environment] 9 | |The Application Environment 10 | 11 | |link:{springapi}org/springframework/core/convert/ConversionService.html[ConversionService] 12 | |link:{micronautapi}core/convert/ConversionService.html[ConversionService] 13 | |For Converting Types 14 | 15 | |link:{springapi}org/springframework/context/ApplicationEventPublisher.html[ApplicationEventPublisher] 16 | |link:{micronautapi}context/event/ApplicationEventPublisher.html[ApplicationEventPublisher] 17 | |For Publishing Events 18 | 19 | |link:{springapi}org/springframework/context/ApplicationContext.html[ApplicationContext] 20 | |link:{micronautapi}context/ApplicationContext.html[ApplicationContext] 21 | |The application context 22 | 23 | |link:{springapi}org/springframework/beans/factory/BeanFactory.html[BeanFactory] 24 | |link:{micronautapi}context/BeanContext.html[BeanContext] 25 | |The bean context 26 | 27 | |=== 28 | 29 | For compatibility the following `Aware` interfaces are supported: 30 | 31 | .Supported `Aware` Interfaces 32 | |=== 33 | 34 | |Spring Interface|Description 35 | 36 | |link:{springapi}org/springframework/context/EnvironmentAware.html[EnvironmentAware] 37 | |For looking up the `Environment` (but prefer `@Autowired`) 38 | 39 | |link:{springapi}org/springframework/context/ApplicationContextAware.html[ApplicationContextAware] 40 | |For looking up the `ApplicationContext` (but prefer `@Autowired`) 41 | 42 | |link:{springapi}org/springframework/beans/factory/BeanFactoryAware.html[BeanFactoryAware] 43 | |For looking up the `BeanFactory` (but prefer `@Autowired`) 44 | 45 | |=== 46 | -------------------------------------------------------------------------------- /src/main/docs/guide/springToMicronaut/springLimitations.adoc: -------------------------------------------------------------------------------- 1 | As mentioned previously only a subset of Spring is implementated, but enough to build real applications. The question you have to ask yourself coming from Spring is how much Spring do you need? 2 | 3 | The following notable features are currently not supported in Micronaut for Spring either and in general if a feature is not documented here consider it unsupported: 4 | 5 | * *AspectJ* - Spring's AOP implementation is not supported, you can however use https://docs.micronaut.io/latest/guide/index.html#aop[Micronaut AOP] which is compilation time and reflection free. 6 | * *Spring Expression Language (SpEL)* - SpEL expressions are not supported, property placeholders are, however. 7 | * *The Servlet API* - Any reference to the Servlet API is not supported 8 | -------------------------------------------------------------------------------- /src/main/docs/guide/springToMicronaut/springToMicronautStart.adoc: -------------------------------------------------------------------------------- 1 | For a build configuration example for Gradle or Maven, see the example project that is part of the guide https://guides.micronaut.io/latest/micronaut-spring-boot.html[Run a Spring Boot Application as a Micronaut Application]. 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/docs/guide/toc.yml: -------------------------------------------------------------------------------- 1 | introduction: Introduction 2 | releaseHistory: Release History 3 | springToMicronaut: 4 | title: Transforming Spring Applications into Micronaut Applications 5 | springToMicronautStart: Build Configuration 6 | springAnnotations: Supported Spring Annotations 7 | springDataAnnotations: Supported Spring Data Annotations 8 | springInterfaces: Supported Spring Interfaces 9 | springEvents: Supported Spring Events 10 | springMvc: Writing Spring MVC Controllers 11 | springBoot: Supported Spring Boot Annotations 12 | springLimitations: Unsupported Spring Features 13 | micronautClient: Using Micronaut's HTTP Client 14 | sharingLibraries: 15 | title: Sharing Libraries between Spring and Micronaut 16 | micronautInsideSpring: 17 | title: Using Micronaut Modules with Spring 18 | springBootStarter: Using the Micronaut Spring Boot Starter 19 | springParentContext: 20 | title: Using Micronaut Parent Context 21 | beanPostProcessor: 22 | title: Using a Bean Post Processor 23 | springGuides: Guides 24 | repository: Repository 25 | -------------------------------------------------------------------------------- /test-suite/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("io.micronaut.build.internal.spring-base") 3 | id("java-library") 4 | id("groovy") 5 | } 6 | 7 | dependencies { 8 | testAnnotationProcessor(projects.micronautSpringAnnotation) 9 | testAnnotationProcessor(mn.micronaut.inject.java) 10 | 11 | testCompileOnly(mn.micronaut.inject.groovy) 12 | 13 | testImplementation(projects.micronautSpring) 14 | testImplementation(mnTest.micronaut.test.spock) 15 | } 16 | 17 | tasks.withType { 18 | useJUnitPlatform() 19 | } 20 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/EventListenerSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx 17 | 18 | import io.micronaut.context.ApplicationContext 19 | import spock.lang.Specification 20 | 21 | class EventListenerSpec extends Specification { 22 | 23 | void "test a transactional event listener is invoked once"() { 24 | given: 25 | ApplicationContext ctx = ApplicationContext.run() 26 | ctx.publishEvent(new FakeEvent()) 27 | 28 | when: 29 | TransactionalListener t = ctx.getBean(TransactionalListener) 30 | 31 | then: 32 | t.invokeCount() == 1 33 | 34 | cleanup: 35 | ctx.close() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/FakeEvent.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx 17 | 18 | class FakeEvent { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/MetaAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx; 17 | 18 | import io.micronaut.context.annotation.DefaultScope; 19 | import jakarta.inject.Singleton; 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.Target; 26 | 27 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 | 29 | @Documented 30 | @Retention(RUNTIME) 31 | @Target({ElementType.TYPE, ElementType.METHOD}) 32 | @Transactional 33 | @DefaultScope(Singleton.class) 34 | public @interface MetaAnnotation { 35 | } 36 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/MetaTransactionalBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx; 17 | 18 | import org.springframework.transaction.TransactionStatus; 19 | import org.springframework.transaction.interceptor.TransactionAspectSupport; 20 | 21 | @MetaAnnotation 22 | public class MetaTransactionalBean { 23 | 24 | public String doSomething() { 25 | // should not throw 26 | final TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus(); 27 | if (transactionStatus == null) { 28 | throw new IllegalStateException("transactionStatus can't be null"); 29 | } 30 | return "foo"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/MockSpringTxSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx 17 | 18 | import io.micronaut.context.ApplicationContext 19 | import spock.lang.Specification 20 | 21 | // simple tests for tx management. More robust tests exist in github.com/micronaut-projects/micronaut-sql 22 | class MockSpringTxSpec extends Specification { 23 | 24 | void "test spring tx management"() { 25 | given: 26 | def ctx = ApplicationContext.run() 27 | TransactionalBean transactionalBean = ctx.getBean(TransactionalBean) 28 | 29 | expect: 30 | transactionalBean.doSomething() == 'foo' 31 | 32 | cleanup: 33 | ctx.close() 34 | } 35 | 36 | void "test meta spring tx management"() { 37 | given: 38 | def ctx = ApplicationContext.run() 39 | MetaTransactionalBean transactionalBean = ctx.getBean(MetaTransactionalBean) 40 | 41 | expect: 42 | transactionalBean.doSomething() == 'foo' 43 | 44 | cleanup:ctx.close() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/MockTransactionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx; 17 | 18 | import jakarta.inject.Singleton; 19 | import org.springframework.transaction.PlatformTransactionManager; 20 | import org.springframework.transaction.TransactionDefinition; 21 | import org.springframework.transaction.TransactionException; 22 | import org.springframework.transaction.TransactionStatus; 23 | import org.springframework.transaction.support.SimpleTransactionStatus; 24 | 25 | @Singleton 26 | public class MockTransactionManager implements PlatformTransactionManager { 27 | 28 | @Override 29 | public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { 30 | return new SimpleTransactionStatus(); 31 | } 32 | 33 | @Override 34 | public void commit(TransactionStatus status) throws TransactionException { 35 | 36 | } 37 | 38 | @Override 39 | public void rollback(TransactionStatus status) throws TransactionException { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/TransactionalBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx; 17 | 18 | import jakarta.inject.Singleton; 19 | import org.springframework.transaction.TransactionStatus; 20 | import org.springframework.transaction.annotation.Transactional; 21 | import org.springframework.transaction.interceptor.TransactionAspectSupport; 22 | 23 | @Singleton 24 | public class TransactionalBean { 25 | 26 | @Transactional 27 | public String doSomething() { 28 | // should not throw 29 | final TransactionStatus transactionStatus = TransactionAspectSupport.currentTransactionStatus(); 30 | if (transactionStatus == null) { 31 | throw new IllegalStateException("transactionStatus can't be null"); 32 | } 33 | return "foo"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test-suite/src/test/groovy/io/micronaut/spring/tx/TransactionalListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 original authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.micronaut.spring.tx; 17 | 18 | import io.micronaut.context.event.ApplicationEventListener; 19 | import jakarta.inject.Singleton; 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | @Singleton 23 | public class TransactionalListener implements ApplicationEventListener { 24 | 25 | private static int invokeCount = 0; 26 | 27 | @Override 28 | @Transactional 29 | public void onApplicationEvent(FakeEvent event) { 30 | invokeCount++; 31 | System.out.println("Hello"); 32 | } 33 | 34 | public int invokeCount() { 35 | return invokeCount; 36 | } 37 | } 38 | --------------------------------------------------------------------------------