Spring Boot: 开发web 应用 - 02 探究竟
2017-06-15 08:22
417 查看
Look Under The Hood
引入了哪些jar 文件
通过pom.xml 可以看到:<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
暂时我们可以忽略掉spring-boot-starter-freemarker,这个只是引入了对freemarker的支持。
打开Dependency Hierarchy可以看看spring-boot-starter-web帮我们引入了哪些jar。
可以从上面看到引入了嵌入式的tomcat;在IDE里面去查询对应的jar文件,spring-boot-starter-* 的jar文件并没有任何的java代码,只是将相关依赖集合起来提供一站式服务。
Starter POMs are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, just include the spring-boot-starter-data-jpa dependency in your project, and you are good to go. Spring Boot Starter POM.
Java 代码
上一节中创建了项目之后,只有两个很简单的Java 类。SpringbootStaticContentApplication
package com.choelea.springboot.springbootstaticcontent; ............. @SpringBootApplication public class SpringbootStaticContentApplication { public static void main(String[] args) { SpringApplication.run(SpringbootStaticContentApplication.class, args); } }
@SpringBootApplication 只是为了方便集合了Spring Boot 常用的几个注解。(最早的Spring Boot没有这个annotation)
The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes. Refer to :Using the @SpringBootApplication annotation
@SpringBootApplication 的入口住类最佳实践是放在最顶级的package中;这样默认所有子package中的class都会被Spring扫到。这点可以查看@ComponentScan 的javadoc “If specific packages are not defined, scanning will occur from the package of the class that declares this annotation. ”
HomePageController
此类只有放在@SpringBootApplication 所在类的下级包内才会被扫描生效。package com.choelea.springboot.springbootstaticcontent.controller; ................. @Controller public class HomePageController { @RequestMapping("/") public String home(){ return "index"; } }
相关文章推荐
- Spring Boot -- Web 应用开发 之 模板引擎
- Spring Boot: 开发web 应用 - 04 静态资源
- Web开发者向桌面应用开发转型之数据结构学习
- [WEB开发][数据库开发/应用]SQL常用命令使用方法
- 昨日关注:Google旧瓶装新酒 用遗弃技术开发Web新应用
- WEB智能应用系统开发运行支撑平台的总体设计(欢迎讨论)
- ASP.NET Web Page应用深入探讨(强烈建议开发web的人学习)
- Web应用开发方式
- 开发web应用难于上青天,web开发十八难
- 基于Web服务的应用、解决方案和开发平台 [转]
- 应用DNS、IIS实现Web项目团队协作开发
- MyEclipse应用:WEB项目的开发
- 团队开发中,如何处理一个站点不同Web应用通用Session
- 应用Struts进行web开发
- 开发web应用难于上青天,web开发十八难
- AJAX开发的性能冲击:使用AJAX提高WEB应用的带宽使用率
- Web应用开发方式(转贴)
- Ajax: Web应用开发的一种新方法
- JSF基于以下的原因简化了基于Web的应用的开发
- 开发web应用难于上青天,web开发十八难