micronaut-projects / micronaut-views

Micronaut Integration with Server Side View Rendering
Apache License 2.0
31 stars 34 forks source link

JTE template should be found and displayed when running as nativeCompile #893

Open kurb70 opened 1 month ago

kurb70 commented 1 month ago

Expected Behavior

JTE template should be found and displayed when running as nativeCompile (macOS).

Actual Behaviour

Only this response appears in the web browser:

{"_links":{"self":[{"href":"/","templated":false}]},"_embedded":{"errors":[{"message":"Internal Server Error: View [example] does not exist"}]},"message":"Internal Server Error"}

On console

 __  __ _                                  _   
|  \/  (_) ___ _ __ ___  _ __   __ _ _   _| |_ 
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| |  | | | (__| | | (_) | | | | (_| | |_| | |_ 
|_|  |_|_|\___|_|  \___/|_| |_|\__,_|\__,_|\__|
12:50:27.127 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 21ms. Server Running: http://localhost:8080
12:50:46.728 [default-nioEventLoopGroup-1-3] INFO  i.m.views.jte.JteViewsRenderer - Using precompiled views.
12:50:46.729 [default-nioEventLoopGroup-1-3] INFO  i.m.views.jte.JteViewsRenderer - Using precompiled views.
12:50:46.729 [default-nioEventLoopGroup-1-3] ERROR i.m.http.server.RouteExecutor - Unexpected error occurred: View [example] does not exist
io.micronaut.views.exceptions.ViewNotFoundException: View [example] does not exist
    at io.micronaut.views.DefaultViewsRendererLocator.lambda$resolveViewsRenderer$1(DefaultViewsRendererLocator.java:71)
    at java.base@21.0.2/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
    at io.micronaut.views.DefaultViewsRendererLocator.resolveViewsRenderer(DefaultViewsRendererLocator.java:60)
    at io.micronaut.views.ViewsFilter.lambda$doFilter$0(ViewsFilter.java:163)
    at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:153)
    at reactor.core.publisher.FluxSwitchMapNoPrefetch.subscribeOrReturn(FluxSwitchMapNoPrefetch.java:61)
    at reactor.core.publisher.Flux.subscribe(Flux.java:8833)
    at io.micronaut.core.async.propagation.ReactivePropagation$1.subscribe(ReactivePropagation.java:55)
    at io.micronaut.core.async.propagation.ReactivePropagation$1.subscribe(ReactivePropagation.java:62)
    at reactor.core.publisher.MonoFromPublisher.subscribe(MonoFromPublisher.java:64)
    at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:76)
    at io.micronaut.http.reactive.execution.ReactorExecutionFlowImpl.onComplete(ReactorExecutionFlowImpl.java:89)
    at io.micronaut.http.server.netty.NettyRequestLifecycle.handleNormal(NettyRequestLifecycle.java:107)
    at io.micronaut.http.server.netty.RoutingInBoundHandler.accept(RoutingInBoundHandler.java:235)
    at io.micronaut.http.server.netty.handler.PipeliningServerHandler$MessageInboundHandler.read(PipeliningServerHandler.java:415)
    at io.micronaut.http.server.netty.handler.PipeliningServerHandler.channelRead(PipeliningServerHandler.java:221)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base@21.0.2/java.lang.Thread.runWith(Thread.java:1596)
    at java.base@21.0.2/java.lang.Thread.run(Thread.java:1583)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)

Steps To Reproduce

  1. create MN app with
curl --location --request GET 'https://launch.micronaut.io/create/default/com.a0d.playground.jtetester.JteTester?lang=JAVA&build=GRADLE&test=SPOCK&javaVersion=JDK_21&features=graalvm&features=views-jte' --output JteTester.zip
  1. Add Controller
    
    package com.a0d.playground.jtetester.controller;

import io.micronaut.core.util.CollectionUtils; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.views.View;

@Controller public class RootController {

@Get("/")
@View("example")
public HttpResponse<?> index() {
    return HttpResponse.ok(CollectionUtils.mapOf("message", "kuba", "showTime", true));
}

}



3. Create native build.
4. Start native build
5. Browse web app

### Environment Information

- Java version: 21.0.2+13, vendor version: GraalVM CE 21.0.2+13.1
- Graal compiler: optimization level: 2, target machine: armv8-a
- C compiler: cc (apple, arm64, 16.0.0)

### Example Application

It is easier to use Micronaut Launch and add this tiny controller from above.

### Version

4.6.2
kurb70 commented 1 month ago

When I start the app via java, the JTE view is displayed without any problems.

kurb70 commented 1 month ago

Ooops I've just realised that I mistakenly claimed that I was using version 4.4.2.

But I was using Micronaut 4.6.2. BTW The problem also occurs with 4.6.3