我按照在线教程在 Eclipse IDE 中创建了一个 spring boot 基本应用程序。当我尝试将该应用程序作为 java 应用程序运行时,该应用程序未部署在嵌入式 tomcat 中。我在谷歌上搜索了很多并尝试了一些找到的解决方案。但是,没有一个对我有用。我在这里粘贴代码。请让我知道任何可能的问题。代码:-
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");
}
}
繁星coding
相关分类