3

I created a new project using Spring Initializr, and opened it with Intellij IDEA version 2020.3.2 ide. After maven installed all dependencies in the pom.xml file, I ran the main method in the DemoApplication class. I didn't add anything new or different than the default project created by the Spring Initializr.

Two Problems occured:

1- Console outputted only these 3 logs, and Tomcat wasn't initialized

2021-02-03 23:48:45.073 INFO 15872 --- [ main] com.example.DemoApplication: Starting DemoApplication using Java 1.8.0_281 on DESKTOP-M with PID 15872 (D:\demo\target\classes started by M in D:\demo)

2021-02-03 23:48:45.078 INFO 15872 --- [ main] com.example.DemoApplication : No active profile set,falling back to default profiles: default

2021-02-03 23:48:46.355 INFO 15872 --- [ main] com.example.DemoApplication: Started DemoApplication in 2.062 seconds (JVM running for 2.87)

Process finished with exit code 0

2- Anything I write in the application.properties file turns grey (unused)

I watched a lot of tutorials, and did exactly as they do. Their console output always has more than 3 statements and is even colored, which mine isn't

My 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

DemoApplication.java

package com.example;

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

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

Would appreciate it if you would help me figure out how to correctly run the project and have the server up and running.

Should I add anymore run Options?

External Libraries:

enter image description here

HR1
  • 487
  • 4
  • 14
  • 1
    Have you got the "Include dependencies with Provided scope" option enabled in the run configuration for your application? Also, probably unrelated to your problem, but you don't need the `commons-logging` dependency and it may interfere with Boot's default logging dependencies. – Andy Wilkinson Feb 03 '21 at 22:23
  • There was an error in the console that stated that this class wasn't found, so I added it. – HR1 Feb 03 '21 at 22:35
  • I enabled the "Include dependencies with Provided scope" option, but still nothing changed. – HR1 Feb 03 '21 at 22:41
  • Please check, whether (simply) **`jar`** fixes this issue, and if you further *need* a war, please consult https://spring.io/guides/gs/convert-jar-to-war/ – xerx593 Feb 03 '21 at 23:09
  • 1
    @xerx593 Unfortunately I tried it and it doesn't fix the issue – HR1 Feb 03 '21 at 23:11
  • 1
    Do you see all the specified dependencies in the External Libraries section of the project view? You don't have the dependency versions specified. – CrazyCoder Feb 03 '21 at 23:11
  • @CrazyCoder yes, I edited the post with a screenshot of the External Libraries section – HR1 Feb 03 '21 at 23:17
  • Do you run via Application or via Maven? Make sure https://i.imgur.com/97RdrDb.png option is disabled. – CrazyCoder Feb 03 '21 at 23:18
  • @CrazyCoder via Maven – HR1 Feb 03 '21 at 23:19
  • Run without Maven using Run option on the left of the main method and [disable Maven delegation](https://i.imgur.com/97RdrDb.png). – CrazyCoder Feb 03 '21 at 23:20
  • @CrazyCoder still same issue – HR1 Feb 03 '21 at 23:23
  • Please zip and share the [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – CrazyCoder Feb 03 '21 at 23:23
  • 1. can reproduce!! (main class, run) solution: run (project) as (maven) `spring-boot:run` – xerx593 Feb 03 '21 at 23:24
  • yea: reproduced&fixed with 2020.3.2 "community edition"... i assume there a missing `spring-boot:repackage` behind the scenes.. – xerx593 Feb 03 '21 at 23:41

3 Answers3

3

This issue is reproducible with a simple war initializer, when you run DemoApplication with a "standalone java" (IDE run) configuration.

The solution/correct usage is: To run (the project) in a "maven" spring-boot:run (IDE run) configuration.

Like:

enter image description here

xerx593
  • 12,237
  • 5
  • 33
  • 64
2

It looks like you are using IntelliJ IDEA Community Edition which has no support for Spring Boot.

That is why the properties are not highlighted and the output is not colored.

IntelliJ IDEA Ultimate will use Spring Boot Run/Debug configuration type automatically:

Boot

As a workaround you can run your code via Maven spring-boot:run.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
0

I saw the same behavior when I setup a project with pox.xml you provided.

The "Include dependencies with "Provided" fixed it for me. However I had to reload the Maven dependencies like this a few times: pom.xml (right click) -> Maven -> Reload Project.

I would still suggest that you remove <scope>provided</scope> in spring-boot-starter-tomcat.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- Comment this out -->
<!-- <scope>provided</scope> -->
</dependency>

Here is a good answer - Java Spring Boot - spring-boot-starter-tomcat dependency doesn't work with scope provided when running locally

If you still need this project to run in an external Tomcat container and thus want to mark the spring-boot-spring-boot-starter dependency as "provided", you can specify a separate profile for that configuration - https://stackoverflow.com/a/42302247

Shankar
  • 2,625
  • 3
  • 25
  • 49