jersey mvc jsp freemarker with embedded tomcat
1.0.0
这是一个简单的应用程序,旨在使用嵌入式的tomcat和Jersey创建休息完整的Web服务,用于配置信息使用YML文件。该应用程序还使用JSP和FreeMarker模板通过REST API调用渲染。它主要集中于将对象实例注册到ResourceConfig而不是注册类。
应用程序创建了两个tomcat上下文路径。一个用于休息的完整API终点为/api ,另一个用于网页的是/webapp ,它直接从Tomcat WebApp Base Directory Location /src/main/webapp加载。
File base = new File("src/main/webapp");
Context context = tomcat.addContext("/api", base.getAbsolutePath());
tomcat.addWebapp(null, "/webapp", base.getAbsolutePath());
此应用程序使用YML文件进行应用程序配置。首先读取Configuration.yml文件,然后将配置传递给应用程序。
#configuration.yml
#setting server configuration
server:
port: 9292
#configure user name
user: "eigenharsha"
ResourceConfig是JAX-RS应用程序类的扩展,但它提供了一些注册方法,以使注册资源和提供商更加友好。此应用程序使用public ResourceConfig register(Object component)通过类实例注册的资源。
JSPMVCFeature和FreeMarkerMvcFeature用于JSP和FreeMarker模板,HTML/Angular/JavaScript直接加载在Web浏览器中。
final ResourceConfig config = new ResourceConfig()
.packages(Main.class.getPackage().getName())
.register(new Resource(new Core(), configuration)) // create instance of Resource and dynamically register
.register(JspMvcFeature.class) // register jspMVC
.register(FreemarkerMvcFeature.class) // register FreemarkerMVC
.property(ServletProperties.FILTER_FORWARD_ON_404, true);
return new ServletContainer(config);
可以在此处提供一个用于构建资源的程序化API的深入教程。
这个项目需要毛门。
$ git clone https://github.com/eigenharsha/jersey-mvc-jsp-freemarker-with-embedded-tomcat.git
$ cd jersey-mvc-jsp-freemarker-with-embedded-tomcat
$ mvn clean install
我创建了一个用于在Heroku上部署的Procfile 。在此处提供了在Heroku上部署的深入教程。
$ web: sh target/bin/webapp
部署此应用程序时,我们将能够访问此REST服务
| 资源 | 端点 |
|---|---|
| 动态创建的资源调用 | http:// localhost:9292/api/资源 |
| 从YML文件获取用户信息 | http:// localhost:9292/api/resource/用户 |
| 自由标记模板 | http:// localhost:9292/api/resource/freemarker |
| JSP模板 | http:// localhost:9292/api/resource/jsp |
| HTML页面 | http:// localhost:9292/webapp/index.html |
问题或建议?请随时通过[email protected]给我发送电子邮件