Custom Micronaut module/jar with auto-configurations
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
add a comment |
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
add a comment |
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
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
maven dependency-injection java-8 micronaut
edited Nov 15 '18 at 13:17
Taras K
asked Nov 12 '18 at 12:07
Taras KTaras K
255
255
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I learned a lot from looking at the handlebars view renderer.
For a configuration in your bean, you need:
- Create an interface with getters for your configuration options.
- Create an implementation of it. Finally, in your bean's constructor,
- 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.
add a comment |
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>
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
I learned a lot from looking at the handlebars view renderer.
For a configuration in your bean, you need:
- Create an interface with getters for your configuration options.
- Create an implementation of it. Finally, in your bean's constructor,
- 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.
add a comment |
I learned a lot from looking at the handlebars view renderer.
For a configuration in your bean, you need:
- Create an interface with getters for your configuration options.
- Create an implementation of it. Finally, in your bean's constructor,
- 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.
add a comment |
I learned a lot from looking at the handlebars view renderer.
For a configuration in your bean, you need:
- Create an interface with getters for your configuration options.
- Create an implementation of it. Finally, in your bean's constructor,
- 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.
I learned a lot from looking at the handlebars view renderer.
For a configuration in your bean, you need:
- Create an interface with getters for your configuration options.
- Create an implementation of it. Finally, in your bean's constructor,
- 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.
answered Nov 12 '18 at 22:13
Mike HoustonMike Houston
1136
1136
add a comment |
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 15 '18 at 13:26
Taras KTaras K
255
255
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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