Springboot(入门)

基于 Maven搭建Springboot框架(入门)

	Spring Boot具有以下优点:

(1)遵循"习惯优于配置"原则,使用Spirng Boot只需很少的配置,大部分时候可以使用默认配置;
(2)项目快速搭建,另外还可以无配置整合第三方框架;
(3)可完全不使用xml配置,只使用自动配置和Java Config;
(4)内嵌入Servlet如Tomcat容器,应用可用jar包运行(java -jar);
(5)运行中应用状态的监控.

因为我是用Idea基于Maven项目集合的Springboot框架,若不会用Idea创建Maven项目,那么请您点这里
https://blog.csdn.net/qq_42090683/article/details/83211430(使用idea创建Maven项目)

一:创建完Maven项目后,则需要在pom.xml中添加Springboot的依赖,然后让它自己把jar包下载完后,就可以下一步了

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<!-- $Id: pom.xml 642118 2008-03-28 08:04:16Z reinhard $ -->
<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>

  <name>demo</name>
  <groupId>test</groupId>
  <artifactId>demo</artifactId>
  <version>1.0-SNAPSHOT</version>

  <!-- Springboot的核心依赖 -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.16.RELEASE</version>
  </parent>

  <!-- 编译级别 -->
  <properties>
    <java.version>1.8</java.version>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

二:需要自己写一个资源文件 application.properties 在resources目录下
在这里插入图片描述

资源文件里面暂时写一个端口号就行

server.port=80`

三:写一个启动类来运行,这个启动类要使它能够扫描所有的包 例如:
在这里插入图片描述
下面贴出启动类的代码块

package com.liufu;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Auther: ${liufu}
 * @Date: 2018/9/16 12:23
 * @Description:
 */
@SpringBootApplication
public class MybatisApplication {
    public static void main(String[] args) {
        SpringApplication.run(MybatisApplication.class,args);

    }
}


下面直接run这个启动类就OK了    运行成功后如以下:

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值