Spring Boot错误找不到Jersey applicationContext.xml

时间:2017-07-23 23:48:46

标签: java spring spring-boot jersey

我正在使用Spring boot和Jersey创建我的第一个项目,这些是我的项目文件, 第一个是Application.java类

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application{

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

}

第二个是HelloResource.java

package hello;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayHello() {
        return "Hello World";
    }
}

,第三个是JerseyConfig.java

package hello;

import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;

import javax.ws.rs.ApplicationPath;

@Component
@ApplicationPath("/")
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig() {
        register(HelloResource.class);
    }
}

使用“mvn spring-boot:run:命令运行应用程序后,我尝试访问此网址”http://localhost:8080/hello“,它显示此错误

java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

0 个答案:

没有答案