- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近看到了一些在 Web 应用程序中使用最新 Spring 的情况。我对如何使用 Tomcat 启动 Spring 应用程序很感兴趣,因为我没有在 web.xml 或另一个调度程序 servlet 中看到任何内容。调度程序 servlet 可能是使用类创建的,但是...如何创建?
最佳答案
我猜当您说在 Web 应用程序中使用最新的 Spring 时,您正在谈论 Spring 4,特别是 Spring Boot .
Spring 是这样描述 Spring Boot 的:
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that can you can "just run".
那么,如何启动并运行独立的 Web 应用程序呢?答案很简单,您在 pom.xml 中声明一些依赖项,添加一个应用程序启动器(一个经典的旧 main
方法),该启动器调用 Spring Boot 中的一个方法,该方法启动整个事情。在这种情况下,整个事情会扫描组件的代码库,然后启动在 pom.xml
中声明的嵌入式容器 (Tomcat) - 之后一切就绪!
应用程序启动器通常会调用启动嵌入式 Web 容器的 SpringApplication.run
方法。您还可以应用一组注释,例如定义应该扫描哪些包或可以使用什么类型的组件。示例包括:@EnableAutoConfiguration
和 @ComponentScan
。各种注释通常可用于替换一些旧的 XML 标签或设置一些不错的默认值 convention over configuration .
来自spring.io blog :
When you run your application, Spring Boot will detect that you have a Spring MVC controller and start up an embedded Apache Tomcat 7 instance, by default.
所以,这基本上意味着 Spring Boot 将启动 Tomcat,但您也可以使用其他容器(例如 Jetty)。
要开始整个过程,只需将以下依赖项添加到您的 pom.xml
中,该项目就启用了 Spring Boot:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.version}</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
然后创建应用程序启动器:
@Controller
@EnableAutoConfiguration
public class IndexController {
@RequestMapping("/")
@ResponseBody
String index() {
return “I am alive”;
}
// The application launcher, starts a simple controller running in the Tomcat container
public static void main(String... args) throws Exception {
// Start an application with your IndexController
SpringApplication.run(IndexController.class, args);
}
}
我真的推荐Spring Boot documentation 。关于这个问题的一些其他有用资源是:
关于java - 在网络应用程序中使用启动 spring 的最新方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27655645/
什么是 Web 服务(Rmi、ejb、soap)? Web服务和Web应用程序有什么区别?是否可以在 Web 应用程序中实现 Web 服务? 最佳答案 Web 服务是一种传输/公开信息的方式,使得可以
典型的 J2ee web 应用程序或任何基于 java 构建的 web 应用程序是多线程应用程序,所以每次我编写一些代码时我都必须牢记竞争条件或并发修改? 最佳答案 Is a typical J2ee
我正在将 google 登录集成到我的网络应用程序中。我按照 here 的说明进行操作。但我无法从登录中获取任何用户信息。不过,登录按钮工作得很好。 我使用这些 JavaScript 函数: i
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
是否有通用 cookie 或其他方式可以检查用户是否登录到谷歌应用程序。然后,如果是这样,我想运行一些 js。如果我知道通常在 Google 应用程序/服务中使用的 cookie 的名称,我就可以读取
我正在尝试以 Web 应用程序样式展示我的记事卡。我不担心缓存或让它离线工作。 我只想让它在 iOS 浏览器中呈现良好。这是链接:http://kaninepete.com/flashcard/rev
我正在使用 bootstrap 制作响应式网络应用。 我开始在我的网站上使用导航栏和表单进行一些测试,问题是 android 中的导航栏,因为它以全宽度呈现(如桌面 View ),而 chrome(对
我正在尝试使用 http://zxing.appspot.com/scan从 WebApp 调用 Barcode Scanner,但我无法让它工作。即使在不必要地更新和重新安装之后,它所做的只是显示默
在 WebStorm 中运行 Dart Web 应用程序时,?底部的 Pane 报告以下内容(--port 因运行而异): /home/tom/dart-sdk/bin/pub serve web -
由于某些原因,我的网络应用程序的路径似乎有问题。 我在 Eclipse 中的 WEB-INF 路径如下: Project --src -- main --webapp
Apps 脚本最近已将 StackDriver 日志移至 Apps Script dashboard ,“执行”页面。 问题是,日志不会显示在 Apps 脚本 Web 应用程序的仪表板中。当我向 Ap
身份验证后,我将用户权限标识符放入用户 session 中。如何根据用户权限限制对网站某些部分的访问。现在我正在检查页面处理程序中的权限,但如何改进? 是否有任何现有的模板可以做到这一点?能举个例子吗
我打算用 GUI 前端编写一个网络应用程序,大概使用 GTK。 我对 GTK(以及一般的 GUI 编程)完全陌生。我目前的猜测是使用两个线程,一个处理网络,另一个运行 GTK 前端。 这是解决此类问题
我一直在办公室工作,我们有一些数据需要处理几次。我的意思是数百行,有时每行中有非常大的文本 block 。为我们的客户说出食谱,其中包含 ID、名称、类别、食谱本身、时间…… 问题是我们需要经常处理和
当谈到使用官方 web SDK 的 Firestore 缓存时,它是否优化了读取以便仅当文档在上次读取后发生更改时才向服务器“发送”读取请求? (因此每次尝试不会生成 1 次额外的文档读取) 为了详细
我开发了一个使用 Jquery 移动框架的移动网络应用程序...我的主页我添加了一个 div,其中包含一些关于谁浏览我的网站 android 设备的说明... Some instructi
我就是这么想的,不知道是不是我 react 慢了。 通常,我将正在编辑的项目的 ID 存储在隐藏字段中。然后在后端(顺便说一句,我正在使用 PHP/Zend Framework),我用它来确定要编辑的
我有一些应用创意想免费发布(带广告)。我是一名 Web 开发人员,目前不想学习 Java/Objective C。我可以轻松地将想法构建到 HTML 5 在线应用程序中。 有什么原因我不能使用 Pho
我正在编写一个网络套接字应用程序,我打算使用 Azure 网络应用程序将其托管在云上。 Web 套接字是使用相当标准的 Owin 中间件实现的,并且在前 100 秒内功能齐全。这段时间之后,webso
是否有任何协议(protocol)可用于在(现在可下载的)谷歌地图中打开地址?这不是 native 应用程序,只是 Safari 的网络应用程序/网站(网络剪辑)。 Google 是否提供任何此类协议
我是一名优秀的程序员,十分优秀!