SpringBoot入门
Posted continued258
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot入门相关的知识,希望对你有一定的参考价值。
Springboot入门当然要用它写一个hello world,这也是我们广大程序员的传统艺能.
首先打开idea ultimate,不要用idea的社区版,社区办没办法使用springboot的插件,需要安装Spring Assistant才行,或者使用maven去建springboot工程.
回到正题,使用idea ultimate去建一个springboot工程.
第一步
创建新工程
选择Spring Initializr
选择next
稍等一下,会出现新建工程的信息,可以适当改一下
next
之后选择,需要用的模块.
Developer Tools ---> Spring Configuration Processor
Web ----> Spring Web
Template Engines ---->Thymeleaf
因为不使用数据库,所以暂时不使用SQL这一项,也可适当更改下Springboot的版本.
next
Finish
打开项目main-->java-->包名,应该是这个样子
maven没问题的话会把需要到依赖都成功导入.
第二步
创建hello world页面
打开src--->main--->resource---->templates
创建html页面
创建文件index
ok
随后打开index.html
在编辑输入hello world
第三步
运行
成功之后下面的控制台会出现这样的日志显示.
随后我们打开浏览器,输入localhost:8080 或者是127.0.0.1:8080 如果一切顺利的话,会出现这样的页面
可能出现的问题:
因为项目非常简单,所以基本上只会在maven自动导入的依赖上,可能导致的情况是,主类下没有绿色的小箭头,不能运行项目.
可能1:maven在下载依赖,下边会出现类似这样的情况
下载时间可能十几分钟也可能非常短,看个人网速.
可能2:maven有问题,需要更改项目使用的maven.可以自己下载一个maven也可以改成别的试试.
左上角File-->Settings
下载速度太慢的话,打开maven的设置文件,改成这样.
项目名右键-->maven--->Open \'settings.xml\'
也可能是Create \'settings.xml\'
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>uk</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> <mirror> <id>CN</id> <name>OSChina Central</name> <url>http://maven.oschina.net/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>nexus</id> <name>internal nexus repository</name> <!-- <url>http://192.168.1.100:8081/nexus/content/groups/public/</url>--> <url>http://repo.maven.apache.org/maven2</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> </settings>
以上是关于SpringBoot入门的主要内容,如果未能解决你的问题,请参考以下文章
全栈编程系列SpringBoot整合Shiro(含KickoutSessionControlFilter并发在线人数控制以及不生效问题配置启动异常No SecurityManager...)(代码片段
SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段