Intellij IDEA下 Spring boot debug配置

1 介绍

Spring Boot 仍然是基于Spring的并且内置Servlet Container , 早去的的容器为Jetty ,最新的容器为Tomcat

Name Servlet Version Java Version

Tomcat 8

3.1

Java 7+

Tomcat 7

3.0

Java 6+

Jetty 9.3

3.1

Java 8+

Jetty 9.2

3.1

Java 7+

Jetty 8

3.0

Java 6+

Undertow 1.3

3.1

Java 7+

Spring boot 把项目打包为jar文件 ,到时候直接运行 java -jar spring-boot01-1.0-SNAPSHOT.jar --server.port=9000 就可以直接运行jar。当然在linux环境下可以nohup java -jar spring-boot01-1.0-SNAPSHOT.jar --server.port=9000 & 来后台运行 。

 2 实战

项目结构


maven 内容 

<?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.jackie</groupId>
    <artifactId>springboottest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.BUILD-SNAPSHOT</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <!-- Add Spring repositories -->
    <!-- (you don't need this if you are using a .RELEASE version) -->
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>
Application.java
package com.jackie;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Created by luhaiming on 2018/1/9 0009.
 */
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Example.java
package com.jackie;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by luhaiming on 2018/1/9 0009.
 */
@RestController
@EnableAutoConfiguration
public class Example {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    @RequestMapping("/hello/{myName}")
    String index(@PathVariable String myName) {
        return "Hello "+myName+"!!!";
    }
}
然后直接运行maven install 命令生成jar 文件就可以按照上面方法来运行了 

Intellij IDEA spring boot run/debug configuration


点击run/debug Edit Configuration




点击+ button 选择Spring Boot


详细配置
只要有 Main class : 配置Spring boot 的入口
VM options:-Xms512m
-Xmx512m
-Xmn164m
-XX:MaxPermSize=250m
-XX:ReservedCodeCacheSize=64m
-Dserver.port=8090
-ea
这样就可以DEBUG 了

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值