2 springboot项目创建(5)

环境要求:jdk1.8+

项目结构:

2.1创建maven工程

Group id :com.springbootdemo

Artifact id: springboot2.0_first_demo

Packaging: jar

2.2pom文件配置

<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.springbootdemo</groupId>
<artifactId>springboot2.0_first_demo</artifactId>
<version>0.0.1-SNAPSHOT</version> <!-- spring-boot-starter-parent 整合第三方常用框架依赖信息(包含各种依赖信息) -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <!-- spring-boot-starter-web springboot整合springmvc web
实现原理:maven依赖继承关系,相当于把第三方常用maven依赖信息,在parent项目中已封装
-->
<dependencies>
<!-- 根据需要选择parent中封装的第三方框架 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 不需要写版本号,因为在parent中已封装好版本号 -->
</dependency>
</dependencies>
</project>

2.3创建测试类及启动类(6)

Springboot启动原理:使用springmvc注解方式启动(不需要xml配置文件)

2.3.1创建启动类和测试类

简洁起见,可将启动类和controller在同一个类中(一般分别创建controller类和启动类)

@RestController
@SpringBootApplication //或使用@EnableAutoConfiguration配置
//@EnableAutoConfiguration //自动配置,根据pom文件引入的依赖信息,自动配置对应的组件;扫包范围,默认在当前类中
public class FirstApplication { @RequestMapping("/test")
public String test(){
return "springboot2.0 first application";
} /**
* 程序入口
* SpringApplication.run 相当于java代码创建内置tomcat,加载springmvc注解启动
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(FirstApplication.class, args);
} }

2.3.2启动springboot项目

1  FirstApplication类--》右键-->run as或debug as--》java app或springboot app。

启动成功日志:

2019-05-12 12:10:58.560  INFO 12436 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-12 12:10:58.563  INFO 12436 --- [           main] com.springboot2demo.FirstApplication     : Started FirstApplication in 2.555 seconds (JVM running for 2.97)

2 页面访问

http://localhost:8080/test

报错:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Apr 14 22:15:23 CST 2019

There was an unexpected error (type=Method Not Allowed, status=405).

Request method 'GET' not supported

Get方式不支持,修改类中的PostMapping为RequestMapping,方便测试。

重启再次访问成功:

springboot2.0 first application

git代码:https://github.com/cslj2013/springboot2.0_log_aop.git

springboot学习入门简易版二---springboot2.0项目创建的更多相关文章

  1. springboot学习入门简易版三---springboot2.0启动方式

    2.4使用@componentscan方式启动 2.4.1 @EnableAutoConfiguration 默认只扫描当前类 @EnableAutoConfiguration 默认只扫描当前类,如果 ...

  2. springboot学习入门简易版四---springboot2.0静态资源访问及整合freemarker视图层

    2.4.4 SpringBoot静态资源访问(9) Springboot默认提供静态资源目录位置需放在classpath下,目录名需要符合如下规则 /static  /public  /resourc ...

  3. springboot学习入门简易版八---springboot2.0多环境配置、整合mybatis mysql8+(19-20)

    2.11 SpringBoot多环境配置(19)  application.properties中配置 Spring.profiles.active=prd 配置环境: Application-dev ...

  4. springboot学习入门简易版六---springboot2.0整合全局捕获异常及log4j日志(12-13)

    使用Aop实现 1创建异常请求 在原有项目基础上,jspController中创建一个可能发生异常的请求: /** * 全局捕获异常测试 * @param i * @return */ @Reques ...

  5. springboot学习入门简易版五---springboot2.0整合jsp(11)

    springboot对jsp支持不友好,内部tomcat对jsp不支持,需要使用外部tomcat,且必须打包为war包. 1 创建maven项目 注意:必须为war类型,否则找不到页面. 且不要把js ...

  6. springboot学习入门简易版九---springboot2.0整合多数据源mybatis mysql8+(22)

    一个项目中配置多个数据源(链接不同库jdbc),无限大,具体多少根据内存大小 项目中多数据源如何划分:分包名(业务)或注解方式.分包名方式类似多个不同的jar,同业务需求放一个包中. 分包方式配置多数 ...

  7. springboot学习入门简易版一---springboot2.0介绍

    1.1为什么用springboot(2) 传统项目,整合ssm或ssh,配置文件,jar冲突,整合麻烦.Tomcat容器加载web.xml配置内容 springboot完全采用注解化(使用注解方式启动 ...

  8. springboot学习入门简易版七---springboot2.0使用@Async异步执行方法(17)

    1启动类开启异步调用注解 @SpringBootApplication @EnableAsync //开启异步调用 public class StartApplication { 不开启则异步调用无效 ...

  9. angular入门一之环境安装及项目创建

    angular入门一之环境安装及项目创建 1.安装node.js 下载,安装,在终端测试安装是否成功:node -v(查看nodejs版本) npm -v(查看npm版本) 下载地址:https:// ...

随机推荐

  1. datax实例——全量、增量同步

    一.全量同步 本文以mysql -> mysql为示例: 本次测试的表为mysql的系统库-sakila中的actor表,由于不支持目的端自动建表,此处预先建立目的表: CREATE TABLE ...

  2. ES6深入浅出-4 迭代器与生成器-3.生成器 & for...of

    迭代器平时用的很少.但是如果你是写框架的,你会经常用到迭代器. 生成器是专门用来做迭代器的东西 发布器是要产生一个叫做next的对象,如果你要产生这种对象.就可以使用ES6新出的语法. ES6的新语法 ...

  3. linux追加所有文件到新的文件(cat)

    例子如下,存在test1.txt, test2.txt, test3.txt,现在准备把这三个文件的内容都追加到testall.txt 中 test1.txt 1 2 3 4 5 6 test2.tx ...

  4. Spring Cloud与Docker微服务架构实战 PDF版 内含目录

    Spring Cloud与Docker微服务架构实战  目录 1 微服务架构概述 1 1.1 单体应用架构存在的问题1 1.2 如何解决单体应用架构存在的问题3 1.3 什么是微服务3 1.4 微服务 ...

  5. 背诵四种清净明诲断淫(愿众生断淫得究竟解脱) (转自学佛网:http://www.xuefo.net/nr/article50/495158.html)

    一.为什么要戒邪淫.断淫欲 <寿康宝鉴>:盖淫念一生,诸念皆起.邪缘未凑生妄心;勾引无计,生机械心;少有阻碍,生嗔恨心;欲情颠倒,生贪着心;羡人有之,生嫉妒心;夺人之爱,生杀害心.廉耻丧尽 ...

  6. Visual Studio 2019 社区版本离线安装

    官方指导 :https://docs.microsoft.com/en-us/visualstudio/install/create-an-offline-installation-of-visual ...

  7. Python 访问一个网址之后输入信息进行检索

    window Python 3 Pycharm软件 from selenium import webdriver #导入Selenium的webdriver from selenium.webdriv ...

  8. ubuntu18.04 安装 wps2019

    安装包可以从官网下载 linuxidc@linuxidc:~/linuxidc.com$ sudo dpkg -i *.deb [sudo] linuxidc 的密码: 正在选中未选择的软件包 wps ...

  9. PHP 与操作判断奇偶

    /** * 判断奇偶数 * @param $n * @return int */ function isOdd($n){ // $a & $b And(按位与) 将把 $a 和 $b 中都为 ...

  10. 021 Android 查询已经导入到工程中的数据库+抖动效果

    1.将数据库(.db)文件放入工程中 在project状态下,新建assets文件夹,并将数据库文件放入assets目录下. 注意:assets目录.java目录.res目录是同级的 new---&g ...