Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Apr 03 13:09
    @jameskleeh banned @orubel
  • Mar 30 18:40
    @graemerocher banned @BeApi_io_twitter
  • Mar 30 08:44
    @graemerocher banned @orubel
Mark Fickett
@mfickett
How do you require a valid OAuth2 access token for a gRPC server endpoint? The Micronaut server docs describe using @Secured(SecurityRule.IS_AUTHENTICATED) but it's for an HTTP server, and doesn't seem to do anything on gRPC endpoints.
Kevin McFadden
@n3bulous

Hey guys, I've been searching hard and haven't determined if what I'm trying to do is possible or not, and if it is how it would be done.

I've read that the annotation classpath is separate from the regular classpath, and it is generated at compile time to avoid scanning the whole classpath.

What I am hoping to do is ship a micronaut jar that loads a 3rd party class at runtime which implements an interface from a shared library known to the micronaut app. Is there a way to accomplish this?

kotrao
@kotrao

Hi, we are upgrading to Micronaut 2.x and we are having some issue on our data layer when using javax.transaction.Transactional annotation. We have two data sources on application.yml one for read only operations and one for read and write. Our repos are annotated with io.micronaut.data.jdbc.annotation.JdbcRepository and also io.micronaut.data.annotation.Repository (with the name of the data source).
The issue is when we can the method annotaed with javax.transaction.Transactional and we are getting : "Multiple possible bean candidates found: [io.micronaut.transaction.jdbc.DataSourceTransactionManager, io.micronaut.transaction.jdbc.DataSourceTransactionManager]" . I was wondening if anyone has encoured the same issue and how to fix it? is there any incomatibility with micronaut data (1.1.1) and Micornaut 2.x?
👆🏻reposting this

@marienik Is this issue resolved? I am facing similar issue. Can you please share the solution if it is resolved.

Kevin McFadden
@n3bulous
When I wrote my question, search hadn't turned up @KevinVanthuyne's discussion from earlier in the day. It's a little orthogonal to my question (he wants to filter out beans, I want to include a class), but you guys discussed ApplicationContextBuilder#packages() being used by JPA to find @Entity. Is this something I can leverage?
Kevin McFadden
@n3bulous
Barring that, is there a better option than distributing the source code in which they add their code?
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
btw, anyone using thymeleaf on micronaut 2.1.2 yet? I started another project with that version, and loading some header tags and header, but it didnt work. Caused by: java.io.FileNotFoundException: ClassLoader resource "views/fragments/home.html" could not be resolved
it was working in 2.1.0
but for a micronaut 2.1.0 project upgraded to 2.1.2, it's working fine
can someone please look into it?
James Kleeh
@jameskleeh
Are you saying it works or doesn’t work in 2.1.2?
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
@jameskleeh doesnt work in 2.1.2
very sorry about that i was testing it out for a bit, assuming that would work from the getgo just like how it is for 2.1.0
James Kleeh
@jameskleeh
If you have an example app that reproduces the problem please file an issue
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
@jameskleeh okay sure
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
James Kleeh
@jameskleeh
@S1lv3rd3m0n_twitter What are the steps to reproduce?
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
just run the project and load localhost:8080
you will notice that the th:block and th:replace was supposed to load the tags, but didnt.
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
btw, congrats on Grails Foundation. Didn't manage to attend the meeting the other day/night
James Kleeh
@jameskleeh
@S1lv3rd3m0n_twitter I am seeing the error on 2.1.0
Seems like the fragments folder isn’t visible to the classloader for some reason
The other folders/files seem to load fine
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
as long as the base of the project started from 2.1.2
James Kleeh
@jameskleeh
I don’t know what that means
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
as in when you started the project with micronaut 2.1.2 instead of 2.1.0
James Kleeh
@jameskleeh
that doesn’t matter
I think your directory name has a space in it
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
okay lemme check
@jameskleeh okay that's bizarre
James Kleeh
@jameskleeh
yep thats it
Kevin H.A. Tan
@S1lv3rd3m0n_twitter
silly me...
how can intellij even allow that to happen lol
okay, consider the issue not valid
thanks again for the help
James Kleeh
@jameskleeh
np
Steven Brown
@Steven-M-Brown

Hopefully this will be a quick one. I'm seeing Cannot convert type [class java.lang.String] to target type: class java.lang.Class. Considering defining a TypeConverter bean to handle this case. when trying to deserialize into a config interface.
The property on the interface is defined as:

@Nonnull
@Bindable(defaultValue = "com.path.stuff.DefaultPredicate")
Class<? extends Predicate<Throwable>> getPredicate();

It worked in 2.0.3 but is not in 2.1.2. I see the TypeConverters are no longer beans but since all the config code was generated I can't inject /control the deserialization. Do I need to do something specific to enable this again?

1 reply
James Kleeh
@jameskleeh
Do you have an example? There is a Charsequence to Class converter added by default
Steven Brown
@Steven-M-Brown
I mean the config that worked is pretty minimal:
@EachProperty("path.configs")
public interface ExampleConfig {
  @Nonnull
  @Bindable(defaultValue = "com.path.stuff.DefaultPredicate")
  Class<? extends Predicate<Throwable>> getPredicate();
}
Used to work in 2.0.3, stopped working in 2.1.2
6 replies
Igor Lu
@AmaranthLIS
hi there, guys I am interesting, how can I setting my config with SPA, when I return index.html as static resource here is good, but then, fronted (SPA) has itself route (URL in browser is changed) and if I make refresh of course I see “Page not found”.
How could I better setting my statics path in Micronaut to always return index.html?!
James Kleeh
@jameskleeh
@AmaranthLIS Something like this:
@Controller
public class ClientForwardController {

    @Inject
    ResourceResolver resourceResolver;

    @Error(global = true, status = HttpStatus.NOT_FOUND)
    @Produces(MediaType.TEXT_PLAIN)
    public Optional<StreamedFile> forward() {
        return resourceResolver.getResource("classpath:static/index.html")
            .map(StreamedFile::new);
    }
}
Igor Lu
@AmaranthLIS
@jameskleeh ow, looks exquisitely! thanks =)
Weiping He
@hewe
Is there a way to prevent a singleton bean's @PostConstruct method to run if that singleton bean is mocked via a @MockBean in unit test environment?
James Kleeh
@jameskleeh
if its mocked then the class shouldn’t be instantiated at all
Weiping He
@hewe
I have eagerSingleton configuration turned on
Weiping He
@hewe
This is what I have and the @PostConstruct method of the singleton still runs even though it is mocked in unit test:
@Introspected
public class TestHandler extends MicronautRequestHandler<String, String> {

    @Inject
    private Dependency dependency;

    @Override
    public String execute(String input) {
        return dependency.getString();
    }
}

@Singleton
public class Dependency {

    @PostConstruct
    public void postConstruct() {
        System.out.println("I do not want this printed in unit test");
    }

    public String getString() {
        return "real getString";
    }
}

@MicronautTest
class TestHandlerTest {

    @MockBean(Dependency.class)
    Dependency mockDependency() {
        return mock(Dependency.class);
    }

    @Inject
    private TestHandler handler;

    @Test
    void execute() {
        handler.execute("test");
    }
}
James Kleeh
@jameskleeh
I thought it had to be @MockBean(Dependency), but could be wrong
Weiping He
@hewe
That didn't change the behavior, I have it as @MockBean(Dependency.class), no change
Weiping He
@hewe
I found a work around for that behavior but it doesn't feel great to do, include within the test class a factory that replaces the real singleton dependency:
    @Factory
    public static class DependencyFactory {

        @Singleton
        @Replaces(Dependency.class)
        public Dependency replaceDependency() {
            return mock(Dependency.class);
        }
    }