简体   繁体   中英

Spring-boot application not getting auto-deployed on startup

I created a spring boot basic application in Eclipse IDE by following a tutorial online. When I am trying to run the application as a java application, the application is not getting deployed in embedded tomcat. I have googled a lot and tried some of the found solutions. However, none worked for me. I am pasting the code here. Please let me know any possible issues. Code:-

pom.xml:-

<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.test</groupId>
<artifactId>spring-boot-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Boot Example</name>
<packaging>jar</packaging>

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



<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>

</dependencies>

SpringBootExample.java:-

package com.test;

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

import com.test.config.AppConfiguration;

@SpringBootApplication
public class SpringBootExample {

    public static void main(String[] args) {
        System.out.println("Started main");
        SpringApplication.run(AppConfiguration.class, args);
        System.out.println("Ending main");
    }

}

AppConfiguration.java:-

package com.test.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.test.beans.SampleBean;

@Configuration
public class AppConfiguration {

    @Bean
    public SampleBean getSampleBean() {
        return new SampleBean();
    }
}

SampleBean.java:-

package com.test.beans;

public class SampleBean {

    public SampleBean() {
        System.out.println("In constructor of SampleBean");
    }

}

Please note that bean of type SampleBean is getting created.But, application is closed after that. Below are the output logs:-

在此处输入图片说明

I added the annotation @EnableAutoConfiguration to AppConfiguration.java and it started working. The application was not able to determine which type of ServletWebServerFactory to create. After adding above annotation, it created it for embedded tomcat already present in classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM