1.springboot介绍
来源:互联网 发布:男人眼中的女神 知乎 编辑:程序博客网 时间:2024/06/05 16:54
1.介绍
简单来说springboot最大的感受在于不用写配置:
web.xml配置
springmvc配置
不用自己安装启动和配置tomcat,springboot已经内嵌
可以和rest风格的微服务契合,快速开发,依赖和程序全打包,jar包启动等优点
maven项目结构:
main/java(这里面放程序,使用app主类启动)
main/resources(这下面放static资源templates资源和application.yml配置文件)
自动引入依赖:springboot自动引入你使用的依赖的依赖
2.helloworld
(1)pom.xml
spring-boot-starter-parent(parent依赖,下面引入的都不需要执行版本)
spring-boot-starter-web
spring-boot-starter-test
spring-boot-maven-plugin(maven打包用的插件)
完整文件如下
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.tyf</groupId> <artifactId>hello-world</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>hello-world</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
(2)app
package com.tyf.hello_world;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.embedded.LocalServerPort;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication //标注启动类@RestController//标注controllerpublic class App {public static void main(String[] args) throws Exception{ SpringApplication.run(App.class, args); }@Bean //static方法执行过程中查看context启动引入的bean public static CommandLineRunner commandLineRunner(ApplicationContext ctx){String[] beanNames = ctx.getBeanDefinitionNames(); for (String beanName : beanNames) { System.out.println(beanName); }return null;}; @RequestMapping("/test")public String test(){return "test" ;} }
启动访问
localhost:8080/test
阅读全文
0 0
- 【SpringBoot】1.SpringBoot介绍
- 1.springboot介绍
- 1.springboot入门开发介绍
- Springboot介绍
- SpringBoot介绍
- Springboot 介绍
- springboot简单介绍
- SpringBoot常用配置介绍
- SpringBoot DevTools 介绍
- SpringBoot常用配置介绍
- 2springboot 配置文件使用介绍
- SpringBoot-dubbo配置信息介绍
- 1.SpringBoot系列-初识SpringBoot
- springboot学习(1)springboot介绍及入门例子
- 使用springBoot的拦截器功能介绍
- SpringBoot系列之一介绍及Helloworld
- springboot应用搭建及简单介绍
- Springboot入门第一篇之身世介绍
- jQuery中$.extend()与$.fn.extend()的区别
- codevs1218疫情控制--noip2012dayt3
- react打包去掉.map文件
- Android使用BitmapRegionDecoder加载超大图片方案
- Oracle的AWR报告分析
- 1.springboot介绍
- 无人驾驶技术与伦理
- Springboot极简教程
- IT项目管理总结一部分小的知识点
- Mybatis连接mysql数据库时中文乱码问题
- 《数字技术》连载10: 第2章 数字器件 第5节 TTL 门电路
- 算法基础【2】OJ网站整理
- 网络工程师必看 OSI七层模型协议
- python+multiprocess+theano+pylucene--内存泄露解决方案