Custom Micronaut module/jar with auto-configurations










0















Can't find a proper working example how to write own modules/libs with auto-configuration.

Can someone explain how to write proper modules for micronaut app?


Tried to load @Factory class and adding package-info.java with @Configuration annotation but that didn't help. Also was adding proper package to scan in main class like this Micronaut.build(args).packages("com.mypackage").start()



Sample:



package com.mypackage;

public class FooService
public void bar()








package com.mypackage;

import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import javax.inject.Singleton;

@Factory
public class FooFactory

@Bean
@Singleton
public FooService fooService()
return new FooService();







//com.mypackage.package-info.java
@Configuration
package com.mypackage;

import io.micronaut.context.annotation.Configuration;









share|improve this question




























    0















    Can't find a proper working example how to write own modules/libs with auto-configuration.

    Can someone explain how to write proper modules for micronaut app?


    Tried to load @Factory class and adding package-info.java with @Configuration annotation but that didn't help. Also was adding proper package to scan in main class like this Micronaut.build(args).packages("com.mypackage").start()



    Sample:



    package com.mypackage;

    public class FooService
    public void bar()








    package com.mypackage;

    import io.micronaut.context.annotation.Bean;
    import io.micronaut.context.annotation.Factory;
    import javax.inject.Singleton;

    @Factory
    public class FooFactory

    @Bean
    @Singleton
    public FooService fooService()
    return new FooService();







    //com.mypackage.package-info.java
    @Configuration
    package com.mypackage;

    import io.micronaut.context.annotation.Configuration;









    share|improve this question


























      0












      0








      0








      Can't find a proper working example how to write own modules/libs with auto-configuration.

      Can someone explain how to write proper modules for micronaut app?


      Tried to load @Factory class and adding package-info.java with @Configuration annotation but that didn't help. Also was adding proper package to scan in main class like this Micronaut.build(args).packages("com.mypackage").start()



      Sample:



      package com.mypackage;

      public class FooService
      public void bar()








      package com.mypackage;

      import io.micronaut.context.annotation.Bean;
      import io.micronaut.context.annotation.Factory;
      import javax.inject.Singleton;

      @Factory
      public class FooFactory

      @Bean
      @Singleton
      public FooService fooService()
      return new FooService();







      //com.mypackage.package-info.java
      @Configuration
      package com.mypackage;

      import io.micronaut.context.annotation.Configuration;









      share|improve this question
















      Can't find a proper working example how to write own modules/libs with auto-configuration.

      Can someone explain how to write proper modules for micronaut app?


      Tried to load @Factory class and adding package-info.java with @Configuration annotation but that didn't help. Also was adding proper package to scan in main class like this Micronaut.build(args).packages("com.mypackage").start()



      Sample:



      package com.mypackage;

      public class FooService
      public void bar()








      package com.mypackage;

      import io.micronaut.context.annotation.Bean;
      import io.micronaut.context.annotation.Factory;
      import javax.inject.Singleton;

      @Factory
      public class FooFactory

      @Bean
      @Singleton
      public FooService fooService()
      return new FooService();







      //com.mypackage.package-info.java
      @Configuration
      package com.mypackage;

      import io.micronaut.context.annotation.Configuration;






      maven dependency-injection java-8 micronaut






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 13:17







      Taras K

















      asked Nov 12 '18 at 12:07









      Taras KTaras K

      255




      255






















          2 Answers
          2






          active

          oldest

          votes


















          0














          I learned a lot from looking at the handlebars view renderer.



          For a configuration in your bean, you need:



          1. Create an interface with getters for your configuration options.

          2. Create an implementation of it. Finally, in your bean's constructor,

          3. Add the configuration interface as an argument.

          When Micronaut creates your bean, it will read the application.yml file and set the values in your configuration impl class. Then it will build your bean with the config value as an argument.






          share|improve this answer






























            0














            The actual problem was in Maven.
            Micronaut Annotation Processor was not triggered by maven-compiler-plugin.



            The solution was to configure annotation processors in maven-compile-plugin:



             <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
            <source>$maven-compiler-plugin.source</source>
            <target>$maven-compiler-plugin.target</target>
            <encoding>$maven-compiler-plugin.encoding</encoding>
            <annotationProcessorPaths>
            <!-- uncomment if you are using lombok -->
            <!-- path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>$lombok.version</version>
            </path -->
            <path>
            <groupId>io.micronaut</groupId>
            <artifactId>micronaut-inject-java</artifactId>
            <version>$micronaut.version</version>
            </path>
            </annotationProcessorPaths>
            </configuration>
            </plugin>





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261873%2fcustom-micronaut-module-jar-with-auto-configurations%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I learned a lot from looking at the handlebars view renderer.



              For a configuration in your bean, you need:



              1. Create an interface with getters for your configuration options.

              2. Create an implementation of it. Finally, in your bean's constructor,

              3. Add the configuration interface as an argument.

              When Micronaut creates your bean, it will read the application.yml file and set the values in your configuration impl class. Then it will build your bean with the config value as an argument.






              share|improve this answer



























                0














                I learned a lot from looking at the handlebars view renderer.



                For a configuration in your bean, you need:



                1. Create an interface with getters for your configuration options.

                2. Create an implementation of it. Finally, in your bean's constructor,

                3. Add the configuration interface as an argument.

                When Micronaut creates your bean, it will read the application.yml file and set the values in your configuration impl class. Then it will build your bean with the config value as an argument.






                share|improve this answer

























                  0












                  0








                  0







                  I learned a lot from looking at the handlebars view renderer.



                  For a configuration in your bean, you need:



                  1. Create an interface with getters for your configuration options.

                  2. Create an implementation of it. Finally, in your bean's constructor,

                  3. Add the configuration interface as an argument.

                  When Micronaut creates your bean, it will read the application.yml file and set the values in your configuration impl class. Then it will build your bean with the config value as an argument.






                  share|improve this answer













                  I learned a lot from looking at the handlebars view renderer.



                  For a configuration in your bean, you need:



                  1. Create an interface with getters for your configuration options.

                  2. Create an implementation of it. Finally, in your bean's constructor,

                  3. Add the configuration interface as an argument.

                  When Micronaut creates your bean, it will read the application.yml file and set the values in your configuration impl class. Then it will build your bean with the config value as an argument.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 '18 at 22:13









                  Mike HoustonMike Houston

                  1136




                  1136























                      0














                      The actual problem was in Maven.
                      Micronaut Annotation Processor was not triggered by maven-compiler-plugin.



                      The solution was to configure annotation processors in maven-compile-plugin:



                       <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>3.8.0</version>
                      <configuration>
                      <source>$maven-compiler-plugin.source</source>
                      <target>$maven-compiler-plugin.target</target>
                      <encoding>$maven-compiler-plugin.encoding</encoding>
                      <annotationProcessorPaths>
                      <!-- uncomment if you are using lombok -->
                      <!-- path>
                      <groupId>org.projectlombok</groupId>
                      <artifactId>lombok</artifactId>
                      <version>$lombok.version</version>
                      </path -->
                      <path>
                      <groupId>io.micronaut</groupId>
                      <artifactId>micronaut-inject-java</artifactId>
                      <version>$micronaut.version</version>
                      </path>
                      </annotationProcessorPaths>
                      </configuration>
                      </plugin>





                      share|improve this answer



























                        0














                        The actual problem was in Maven.
                        Micronaut Annotation Processor was not triggered by maven-compiler-plugin.



                        The solution was to configure annotation processors in maven-compile-plugin:



                         <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.8.0</version>
                        <configuration>
                        <source>$maven-compiler-plugin.source</source>
                        <target>$maven-compiler-plugin.target</target>
                        <encoding>$maven-compiler-plugin.encoding</encoding>
                        <annotationProcessorPaths>
                        <!-- uncomment if you are using lombok -->
                        <!-- path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>$lombok.version</version>
                        </path -->
                        <path>
                        <groupId>io.micronaut</groupId>
                        <artifactId>micronaut-inject-java</artifactId>
                        <version>$micronaut.version</version>
                        </path>
                        </annotationProcessorPaths>
                        </configuration>
                        </plugin>





                        share|improve this answer

























                          0












                          0








                          0







                          The actual problem was in Maven.
                          Micronaut Annotation Processor was not triggered by maven-compiler-plugin.



                          The solution was to configure annotation processors in maven-compile-plugin:



                           <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-compiler-plugin</artifactId>
                          <version>3.8.0</version>
                          <configuration>
                          <source>$maven-compiler-plugin.source</source>
                          <target>$maven-compiler-plugin.target</target>
                          <encoding>$maven-compiler-plugin.encoding</encoding>
                          <annotationProcessorPaths>
                          <!-- uncomment if you are using lombok -->
                          <!-- path>
                          <groupId>org.projectlombok</groupId>
                          <artifactId>lombok</artifactId>
                          <version>$lombok.version</version>
                          </path -->
                          <path>
                          <groupId>io.micronaut</groupId>
                          <artifactId>micronaut-inject-java</artifactId>
                          <version>$micronaut.version</version>
                          </path>
                          </annotationProcessorPaths>
                          </configuration>
                          </plugin>





                          share|improve this answer













                          The actual problem was in Maven.
                          Micronaut Annotation Processor was not triggered by maven-compiler-plugin.



                          The solution was to configure annotation processors in maven-compile-plugin:



                           <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-compiler-plugin</artifactId>
                          <version>3.8.0</version>
                          <configuration>
                          <source>$maven-compiler-plugin.source</source>
                          <target>$maven-compiler-plugin.target</target>
                          <encoding>$maven-compiler-plugin.encoding</encoding>
                          <annotationProcessorPaths>
                          <!-- uncomment if you are using lombok -->
                          <!-- path>
                          <groupId>org.projectlombok</groupId>
                          <artifactId>lombok</artifactId>
                          <version>$lombok.version</version>
                          </path -->
                          <path>
                          <groupId>io.micronaut</groupId>
                          <artifactId>micronaut-inject-java</artifactId>
                          <version>$micronaut.version</version>
                          </path>
                          </annotationProcessorPaths>
                          </configuration>
                          </plugin>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '18 at 13:26









                          Taras KTaras K

                          255




                          255



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261873%2fcustom-micronaut-module-jar-with-auto-configurations%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kleinkühnau

                              Makov (Slowakei)

                              Deutsches Schauspielhaus