6

I am not able to run my Spring Boot application with embedded Tomcat. It was working fine till now and I did not make any changes in configuration. When i run the application as Spring Boot App in eclipse the tomcat stops immediately during startup.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2019-02-06 14:12:20,103 restartedMain ERROR Console contains an invalid element or attribute ""

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.6.RELEASE)

Feb 06, 2019 2:12:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Feb 06, 2019 2:12:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.16
Feb 06, 2019 2:12:24 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Feb 06, 2019 2:12:24 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
2019-02-06 14:12:24.946  INFO 9504 --- [  restartedMain] o.h.j.i.u.LogHelper                      : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-02-06 14:12:25.031  INFO 9504 --- [  restartedMain] o.h.Version                              : HHH000412: Hibernate Core {5.0.12.Final}
2019-02-06 14:12:25.034  INFO 9504 --- [  restartedMain] o.h.c.Environment                        : HHH000206: hibernate.properties not found
2019-02-06 14:12:25.036  INFO 9504 --- [  restartedMain] o.h.c.Environment                        : HHH000021: Bytecode provider name : javassist
2019-02-06 14:12:25.089  INFO 9504 --- [  restartedMain] o.h.a.c.Version                          : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-02-06 14:12:25.410  INFO 9504 --- [  restartedMain] o.h.d.Dialect                            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Feb 06, 2019 2:12:27 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]

I tried restarting machine, eclipse, refreshing project, recreate the .m2 repositories but it did not help me solve the problem.

Below is my configuration information:

Main Class

@SpringBootApplication
@PropertySource(value="classpath:messages.properties")
public class ExampleApplication {

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

}

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.brokerswing</groupId>
    <artifactId>brokerswing</artifactId>
    <version>1.1</version>

    <name>Example</name>
    <description>-</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Spring Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Spring Data JPA -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- Spring Email -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- Spring Development Tools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Servlet+JSP+JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

        <!-- Commons Collection -->
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </dependency>

        <!-- Simple Java Mail -->
        <!-- <dependency> <groupId>org.simplejavamail</groupId> <artifactId>simple-java-mail</artifactId> 
            <version>4.4.5</version> </dependency> -->

        <!-- Java Mail and JAF -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
            <scope>provided</scope>
        </dependency>

        <!-- Apache Velocity -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>

        <!-- Apache Log4j 2 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
        </dependency>

        <!-- Excel library -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.6</version>
        </dependency>

    </dependencies>

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

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <packaging>war</packaging>

</project>

Application.properties

# IDENTITY (ContextIdApplicationContextInitializer)
spring.application.name=Example

server.port=80
#debug=true

# SPRING MVC (WebMvcProperties)
spring.mvc.date-format=DD/MM/YYYY

# JDBC Connection
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/brokerswing?useSSL=false
spring.datasource.username=root
spring.datasource.password=root


# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=false   
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext


# DEVTOOLS (DevToolsProperties)
spring.devtools.restart.enabled=true
spring.devtools.restart.exclude=META-INF/maven/**,META-INF/resources/**,resources/**,static/**,public/**,templates/**,**/*Test.class,**/*Tests.class,git.properties,META-INF/build-info.properties
spring.devtools.restart.poll-interval=5000
spring.devtools.restart.quiet-period=1000
Nishant Singh
  • 135
  • 1
  • 1
  • 15

5 Answers5

6

The error you get seems related to SLF4J

Try adding the below dependencies in your pom.xml

  <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.5</version>
   </dependency>
nullPointer
  • 4,419
  • 1
  • 15
  • 27
  • Thanks a lot. Your solution worked. By adding the above dependency i was able to view the description of the error. In my case, one of the method was accidentally assigned a @bean annotation whereas its purpose was not to create a bean :) – Nishant Singh Feb 06 '19 at 09:33
2

In my case, @Service annotation was missing from one of my services. I added the below dependency in my pom.xml (as suggested above) which helped me to get the required error log to resolve the issue.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.5</version>
</dependency>
Shipra
  • 91
  • 1
  • 4
  • In my case it was an absent `@Component` annotation on a DAO class. Though IDE highlighted it with red, the compiler built without errors and this was not mentioned anywhere in logs. If someone knows where this error info might be found, please point it. Thanks. – Rostyslav Druzhchenko Aug 03 '22 at 06:15
0

In my case, the issue's cause was a wrong configuration of log4j due mainly to a missing necessary dependency commons-collections

The maven configuration of the dependency:

<dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.0</version>
</dependency>

Hope this addition helps other visitors.

jmj
  • 649
  • 8
  • 17
0

There may be a chance that the tomcat port may be occupied, so please try the below command in cmd or terminal to find the occupied port, stop that, and try running your app once.

  1. netstat -ano | findstr :<Tomcat-Port-No>

    netstat Tomcat-Port-No execution output example

  2. taskkill /PID <PID> /F

    taskkill execution output example

ErikE
  • 48,881
  • 23
  • 151
  • 196
0

In my case it happened because of a standalone Tomcat instance has been run. Since it was ran as a brew service it rerun even after an appropriate process was killed. To get rid off it just run in terminal

brew services stop tomcat

or another command that suits your operating system to stop Tomcat service.

Can guess that someone may face with this issue because of running any other java application process, such as Jenkins for instance.

To find a process that occupied your port (on macos) you may use

sudo lsof -i -P | grep LISTEN | grep :$PORT

as suggested here.

Rostyslav Druzhchenko
  • 3,673
  • 3
  • 33
  • 38