SpringBoot学习:在Interillj Idea上快速搭建SpringBoot项目
一、创建SpringBoot项目
二、导入Jar包(pom.xml)
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>testdemo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>TestDemo1</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.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.7</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> <!--引入配置文件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency> <!--添加mysql的组件-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> <!--servlet依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency> <!--jstl依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency> <!--使jsp页面生效-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency> <!--整合mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency> </dependencies> <build>
<plugins>
<!--将SpringBoot的Maven插件全部引入 包含tomcat-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
三、配置yml文件、启动类
application.yml内容:
server:
#服务端口
port: 8080
#项目contextPath,一般在正式发布版本中,不配置,目前配置缺省路径
context-path: /
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
#address: 192.168.0.101
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
# error:
# path: /error
# session最大超时时间(分钟),默认为30
#session:
# timeout: 60
# tomcat:
# tomcat的URI编码
#uri-encoding: utf-8
# tomcat最大线程数,默认为200
#max-threads: 1000
# 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
#basedir: D:/springboot-tomcat-tmp
# 打开Tomcat的Access日志,并可以设置日志格式的方法:
#server.tomcat.access-log-enabled=true
#server.tomcat.access-log-pattern=
application.java启动类:
---- spring会扫描该类所在目录下的java类,SpringBoot唯一入口程序
package com.example.demo; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class TestDemo1Application {
/*
Servlet容器默认的Context路径是/DispatherServlet匹配的路径(servlet-mapping中的url-patterns)
@ComponentScan路径被默认设置为SampleController的同名package,
也就是该package下的所有@Controller,@Service, @Component, @Repository都会被实例化后并加入Spring Context中。
*/
public static void main(String[] args) {
SpringApplication.run(TestDemo1Application.class, args);
}
}
Controller类:
package com.example.demo.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; /**
* Created by Administrator on 2017/7/19.
*/
@Controller
public class ControllerDemo {
@RequestMapping("/index")
// @ResponseBody
public String getDemo(){
System.out.println(".....");
return "index";
}
}
访问localhost:8080/index 即可在页面中打印出 “index” 字样。
注意:在创建Controller类时,所有的类都得是默认包的子孙包。
SpringBoot学习:在Interillj Idea上快速搭建SpringBoot项目的更多相关文章
- 【SpringBoot学习一】开发入门--快速创建springboot程序
前言 本片博客记录快速创建springboot工程的两种方式.一种是使用maven创建,一种是使用spring initializr创建.开发环境JDK1.8.IDEA.maven. SpringBo ...
- SpringBoot学习(一)—— idea 快速搭建 Spring boot 框架
简介 优点 Spring Boot 可以以jar包的形式独立运行,运行一个Spring Boot 项目只需要通过 java -jar xx.jar 来运行. Spring Boot 可以选择内嵌Tom ...
- WAMP Server助你在Windows上快速搭建PHP集成环境
WAMP Server助你在Windows上快速搭建PHP集成环境 原文地址 我想只要爬过几天网的同学都会知道PHP吧,异次元的新版本就是基于PHP的WordPress程序制造出来的,还有国内绝大部分 ...
- 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置
1.快速搭建springboot框架(在idea中): file–>new project–>Spring Initializr–>next–>然后一直下一步. 然后复制一下代 ...
- 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...
- VMware 克隆linux后找不到eth0(学习hadoop,所以想快速搭建一个集群)
发生情况: 由于在学习hadoop,所以想快速搭建一个集群出来.所以直接在windows操作系统上用VMware安装了CentOS操作系统,配置好hadoop开发环境后,采用克隆功能,直接克 ...
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse
笔记 1.快速搭建SpringBoot项目,采用Eclipse 简介:使用SpringBoot start在线生成项目基本框架并导入到eclipse中 1.站点地址:http://start. ...
- 使用IDEA快速搭建Springboot项目
Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 下面就介绍一下如何使用idea快速搭建 ...
- 聊聊SpringBoot | 第一章:快速搭建SpringBoot第一个应用
快速搭建SpringBoot第一个应用 1.简介 本章仅介绍如何快速搭建第一个SpringBoot应用,细节内容下一章再做讲解,如果有需要,各位可以直接到Spring官网去了解. 从 Spring B ...
随机推荐
- Python爬虫学习笔记之点触验证码的识别
代码: Chaojiying.py: #!/usr/bin/env python # coding:utf-8 import requests from hashlib import md5 clas ...
- maven中jar包的maven地址查询
在网站 https://mvnrepository.com/ 中查找.
- 8.IO模型
一.事件驱动模型 服务器处理模型程序,通常有以下几种: (1)收到一个请求则创建一个新的进程来处理这个请求 (2)收到一个请求则创建一个新的线程来处理这个请求 (3)收到一个请求,把它放入事件列表,让 ...
- 数学:拓展BSGS
当C不是素数的时候,之前介绍的BSGS就行不通了,需要用到拓展BSGS算法 方法转自https://blog.csdn.net/zzkksunboy/article/details/73162229 ...
- How GitLab uses Unicorn and unicorn-worker-killer
GitLab uses Unicorn, a pre-forking Ruby web server, to handle web requests (web browsers and Git HTT ...
- Druid连接池及监控在spring中的配置
Druid连接池及监控在spring配置如下: <bean id="dataSource" class="com.alibaba.druid.pool.DruidD ...
- R、Python、Scala和Java,到底该使用哪一种大数据编程语言?
有一个大数据项目,你知道问题领域(problem domain),也知道使用什么基础设施,甚至可能已决定使用哪种框架来处理所有这些数据,但是有一个决定迟迟未能做出:我该选择哪种语言?(或者可能更有针对 ...
- SQL SERVER 创建远程数据库链接 mysql oracle sqlserver
遇到的坑 在连接Oracle时,因为服务器为10g 32位版本,然后在本地安装了32为10g客户端,然后一直报错[7302.7303],后来下载了12c 64位版本,安装成功后,问题解决 原因:mss ...
- ImageView设置边框 以及内部图片居中显示 在AndroidStudio中添加shape.xml文件
效果如图 边框设置:shape文件 <shape xmlns:android="http://schemas.android.com/apk/res/android"> ...
- SpringBoot工程目录配置
Spring Boot建议的目录结果如下: root package结构:com.example.myproject com +- example +- myproject +- Applicat ...