dabla / grizzly-spring-boot-starter

Apache License 2.0
5 stars 1 forks source link

Spring MVC controller cannot take effect #6

Open xiaohanfeidao opened 2 years ago

xiaohanfeidao commented 2 years ago

Hey,

I integrated grizzly starter in my project,The codes are as follows:

org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat
    <dependency>
        <groupId>be.dabla</groupId>
        <artifactId>grizzly-spring-boot-starter</artifactId>
        <version>2.7</version>
    </dependency>

@SpringBootApplication public class App { public static void main( String[] args ) { SpringApplication.run(App.class, args); }

@Bean
public ResourceConfigCustomizer resourceConfigCustomizer() {
    return new ResourceConfigCustomizer() {
        @Override
        public void customize(ResourceConfig resourceConfig) {
            Map<String,Object> properties = new HashMap<>();
            properties.put("com.sun.jersey.api.json.POJOMappingFeature", "true");
            properties.put("com.sun.jersey.config.feature.trace", "ALL");
            resourceConfig.addProperties(properties);
        }
    };
}

}

spring mvc controller file: import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;

/**

application.yml: spring: application: name: app-grizzly jersey: application-path: /jersy

server: port: 8082 servlet: context-path: /

The startup log is as follows:

2022-06-23 14:33:30.483 INFO 24620 --- [ main] b.d.b.g.config.GrizzlyAutoConfiguration : Running with Grizzly Spring Boot Starter v2.7 2022-06-23 14:33:30.683 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Initializing Spring embedded WebApplicationContext 2022-06-23 14:33:30.683 INFO 24620 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 902 ms 2022-06-23 14:33:30.702 WARN 24620 --- [ main] b.d.boot.grizzly.http.HttpServerFactory : java.lang.UnsupportedOperationException: Not supported yet. 2022-06-23 14:33:30.703 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : Starting application [application] ... 2022-06-23 14:33:31.162 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Servlet [org.glassfish.jersey.servlet.ServletContainer] registered for url pattern(s) [[/jersy/]]. 2022-06-23 14:33:31.164 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-06-23 14:33:31.164 INFO 24620 --- [ main] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-06-23 14:33:31.324 INFO 24620 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2022-06-23 14:33:31.379 INFO 24620 --- [ main] o.s.web.servlet.DispatcherServlet : Completed initialization in 215 ms 2022-06-23 14:33:31.379 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Servlet [org.springframework.web.servlet.DispatcherServlet] registered for url pattern(s) [[/]]. 2022-06-23 14:33:31.380 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Filter [org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter] registered for url pattern(s) [[/]] and servlet name(s) [[]] 2022-06-23 14:33:31.380 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Filter [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter] registered for url pattern(s) [[/]] and servlet name(s) [[]] 2022-06-23 14:33:31.381 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Filter [org.springframework.web.filter.RequestContextFilter] registered for url pattern(s) [[/]] and servlet name(s) [[]] 2022-06-23 14:33:31.381 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : Application [application] is ready to service requests. Root: []. 2022-06-23 14:33:31.664 INFO 24620 --- [ main] o.g.grizzly.http.server.NetworkListener : Started listener bound to [0.0.0.0:8082] 2022-06-23 14:33:31.666 INFO 24620 --- [ main] o.g.grizzly.http.server.HttpServer : [HttpServer] Started.

Access error:

image

dabla commented 2 years ago

Hello, I see you have defined following in YAML file:

jersey: application-path: /jersy

This is also shown in you logging above:

2022-06-23 14:33:31.162 INFO 24620 --- [ main] o.g.grizzly.servlet.WebappContext : [application] Servlet [org.glassfish.jersey.servlet.ServletContainer] registered for url pattern(s) [[/jersy/]].

So try following path: http://localhost:8082/jersy/hello

dabla commented 2 years ago

Also if you want to use the Spring REST controllers instead of Jersey (which is the default for Grizzly), then you need to specify following parameter in your YAML file as stated in the README.md, see the section concerning it.

spring.jersey.application-path=/api

xiaohanfeidao commented 2 years ago

Hey,In this way, the access also returns error

1655972197(1)

According to the wiki guidelines, I only need to distinguish the root path of spring MVC and Jersy, You can see that I have distinguished the root path between spring MVC and Jersey。

image

image

I still can't find the wrong configuration,hope to get your help,thanks。

dabla commented 2 years ago

That's the issue, as already stated:

Since version 2.6 it is possible to use the Spring REST controllers instead of the default Jersey JAX-RS implementation. To be able to do so, make sure you specify the spring.jersey.application-path property to a specific path which is different than the root (e.g. /) otherwise there will be a path conflict and requests will never be able to reach the Spring DispatcherServlet.

Try setting it to /api as I said before and see if that works, it won't work when registered to the root due to the fact how Grizzly internal works.