内嵌Jetty集成SpringMVC提供HTTP服务

本文介绍如何在项目中内嵌Jetty服务器并结合SpringMVC,提供HTTP服务。首先列出核心jar包需求,接着展示基于Java的配置方法,包括MVC和应用配置。接着详细说明启动函数的编写,以及如何在Spring上下文中配置启动函数以处理HTTP服务。文章还提及了可能遇到的ApplicationContext冲突问题,并给出了解决方案。
摘要由CSDN通过智能技术生成

项目中需要内嵌Jetty提供HTTP服务,并且需要基于SpringMVC实现MVC模式和Restful接口。实现方案如下所示。

需要的jar包

本方案需要的核心jar包如下(其他jar包自行补充):

jackson-annotations-2.9.5.jar
jackson-core-2.9.5.jar
jackson-databind-2.9.5.jar
jetty-all-9.4.10.v20180503-uber.jar
spring-aop-4.3.16.RELEASE.jar
spring-aspects-4.3.16.RELEASE.jar
spring-beans-4.3.16.RELEASE.jar
spring-context-4.3.16.RELEASE.jar
spring-context-support-4.3.16.RELEASE.jar
spring-core-4.3.16.RELEASE.jar
spring-expression-4.3.16.RELEASE.jar
spring-web-4.3.16.RELEASE.jar
spring-webmvc-4.3.16.RELEASE.jar
spring-websocket-4.3.16
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
我理解您的问题是如何在JDK17中内嵌Jetty11并配置JSP界面。首先,需要在项目中添加Jetty11的依赖,例如Maven项目可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>11.0.6</version> </dependency> ``` 然后,在代码中启动Jetty11并配置JSP界面,可以参考以下示例代码: ```java import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; public class EmbeddedJetty { public static void main(String[] args) throws Exception { Server server = new Server(8080); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setResourceBase("src/main/webapp"); webapp.setClassLoader(Thread.currentThread().getContextClassLoader()); webapp.setConfigurationClasses(new String[]{"org.eclipse.jetty.webapp.WebInfConfiguration", "org.eclipse.jetty.webapp.WebXmlConfiguration"}); webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*jstl.*\\.jar$"); webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*taglibs.*\\.jar$"); webapp.setDescriptor("src/main/webapp/WEB-INF/web.xml"); webapp.setParentLoaderPriority(true); server.setHandler(webapp); server.start(); server.join(); } } ``` 此代码将在8080端口启动Jetty11并将Web应用程序部署在src/main/webapp目录下。在此目录下,您可以创建一个JSP文件并通过http://localhost:8080/访问它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值