Run Spring-boot's main using IDE

前端 未结 9 1840
灰色年华
灰色年华 2020-11-30 01:51

I have a spring-boot application that needs to:

  • Be deployable as a war in a servlet container
  • Be runnable via `mvn spring-boot:run``

I\

相关标签:
9条回答
  • 2020-11-30 02:31

    I was able to work around this problem in Intellij IDEA 2017.2 by adding the provided libaray (spring-boot-starter-tomcat) to the project configuration.

    Select File -> Project Structure. Select Libraries and add a new project library (type = From Maven...). Search for spring-boot-starter-tomcat using the dialog, select the correct version and add it by clicking on OK. The library is added to the list of external libraries.

    The disadvantage is that if the Spring Boot version is changed then you will have to remember to delete this library and add the new version.

    0 讨论(0)
  • 2020-11-30 02:32

    I had the same problem using IntelliJ 2018. Initially, Make sure that you have added the maven library for the spring project in your IntelliJ.

    My solution is:

    1. Go to Run -> Edit Configurations.

    2. Select Application && choose your current project.

    3. Check Include dependencies with "Provided" scope.

    4. OK -> RUN

    0 讨论(0)
  • 2020-11-30 02:34

    I find this page, and use the maven profile to manage the profiles.

        <profiles>
                  <profile>
                       <id>PROD</id>
                       <dependencies>
                            <dependency>
                                 <groupId>org.springframework.boot</groupId>
                                 <artifactId>spring-boot-starter-tomcat</artifactId>
                                 <scope>provided</scope>
                            </dependency>
                       </dependencies>
                  </profile>
    <profile>
                       <id>DEV</id>
                       <dependencies>
                            <dependency>
                                 <groupId>org.springframework.boot</groupId>
                                 <artifactId>spring-boot-starter-tomcat</artifactId>
                                 <scope>TEST</scope>
                            </dependency>
                       </dependencies>
                  </profile>
             </profiles>
    

    and config the main class beforeLanuce,set the command

    mvn clean compile -Pdev
    
    0 讨论(0)
提交回复
热议问题