Spring boot application won't run when trying to run from the jar file

前端 未结 3 1836
别跟我提以往
别跟我提以往 2020-12-11 17:13

I have a spring boot application which works fine when run through intellij. But when I run it from the jar I am getting the below exception.

        2017-02         


        
3条回答
  •  萌比男神i
    2020-12-11 17:37

    @abaghel answer has the correct explanation, and arguably the best solution as well.

    Since Jersey's scanning step is what's failing, another way to work around it is to explicitly register each resource. I replaced this:

    @Component
    public JerseyConfig() extends ResourceConfig {
        packages("com.mydomain.resource");
    }
    

    with

    @Component
    public JerseyConfig() extends ResourceConfig {
        register(TimeResource.class);
        register(SpaceResource.class);
        // etc.
    }
    

    (Tested with Spring Boot 2.1.3)

    My code has about 25 Jersey of these resource classes to register. This highlights the downside to this approach, namely that the explicit registration has to be maintained. New resource classes won't be found automatically, and it can be a confusing error to run into.

    On the other hand, you don't need to split your project up. So explicit registration might occasionally be good enough.

提交回复
热议问题