gpt4 book ai didi

java - Spring 靴 Jersey : resources not autodiscover

转载 作者:搜寻专家 更新时间:2023-11-01 03:02:25 24 4
gpt4 key购买 nike

我尝试将 Spring-boot 与 jetty 和 jersey 一起使用。 jetty 部分没问题。我可以启动服务器并且 spring 资源正在运行(跟踪、指标、信息、bean 等),但我的资源没有运行。

我的配置文件是:启动器.java

@Configuration
@PropertySource("classpath:application.properties")
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.fdilogbox.report.serveur"})
public class Launcher extends SpringBootServletInitializer {

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Launcher.class);
}

@Bean
public ServletRegistrationBean jerseyServlet() {
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/api/*");
registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, ResourcesConfiguration.class.getName());
return registration;
}

@Bean
public EmbeddedServletContainerFactory containerFactory() {
final JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory = new JettyEmbeddedServletContainerFactory() {
@Override
protected JettyEmbeddedServletContainer getJettyEmbeddedServletContainer(Server server) {
return new JettyEmbeddedServletContainer(server);
}
};
jettyEmbeddedServletContainerFactory.addServerCustomizers(new JettyConfiguration());
return jettyEmbeddedServletContainerFactory;
}

@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}

JettyConfiguration.java

public class JettyConfiguration implements JettyServerCustomizer {

@Override
public void customize(Server server) {
WebAppContext webAppContext = (WebAppContext) server.getHandler();
try {
// Load configuration from resource file (standard Jetty xml configuration) and configure the context.
createConfiguration("/jetty.xml").configure(webAppContext);
createConfiguration("/jetty-rewrite.xml").configure(server);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private XmlConfiguration createConfiguration(String xml) throws IOException, SAXException {
return new XmlConfiguration(Launcher.class.getResourceAsStream(xml));
}
}

资源配置.java

public class ResourcesConfiguration extends ResourceConfig {

public ResourcesConfiguration() {
super();

PackageNamesScanner resourceFinder = new PackageNamesScanner(new String[]{"com.fdilogbox.report.serveur.business.resources"}, true);
registerFinder(resourceFinder);
register(JacksonFeature.class);
}
}

和我的资源文件:

@Path("builder")
@Component
public class ReportBuilderResource {

@Autowired
private ReportBuilderService reportBuilderService;

@GET
@Path("list")
@Produces(MediaType.APPLICATION_JSON)
public String[] findAll() {
return reportBuilderService.findAllReport();
}
}

如果我尝试访问“localhost:9090/api/builder/list”,我会收到 404 错误。但是如果我尝试“localhost:9090/bean”,我会得到所有 JSON 格式的 bean。

我想我的 conf 中有错误,但我不知道在哪里。

最佳答案

我发现我的错误:管理端口是 9090 但正常资源端口是 8090。

关于java - Spring 靴 Jersey : resources not autodiscover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com