Java 使用EclipseTomcat运行Spring引导
我试图用EclipseTomcat启动SpringBoot,但失败了 我将Eclipse与以下插件一起使用Java 使用EclipseTomcat运行Spring引导,java,spring,eclipse,spring-boot,Java,Spring,Eclipse,Spring Boot,我试图用EclipseTomcat启动SpringBoot,但失败了 我将Eclipse与以下插件一起使用 BuildShip Gradle集成2.0 弹簧工具3附加3.9.6版本 我用Spring Boot创建了我的项目 类型:gradle(BuildShip 2.x) 包装:战争 Java版本:8 语言:Java 这是我的身材。格雷德尔: buildscript { ext { springBootVersion = '2.1.0.RELEASE' }
- BuildShip Gradle集成2.0
- 弹簧工具3附加3.9.6版本
- 类型:gradle(BuildShip 2.x)
- 包装:战争
- Java版本:8
- 语言:Java
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'heykj.web'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testImplementation('org.springframework.boot:spring-boot-starter-test')
//providedCompile "javax.servlet:javax.servlet-api:4.0.1"
}
这是我的应用程序类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class PlusFApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(PlusFApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PlusFApplication.class);
}
}
我的项目方面:
我不明白为什么这不起作用。我认为EclipseTomcat找不到主类。我添加了servlet api,但它不起作用。我怎样才能解决它 对不起!有一些打字错误,我错过了我的处境。
首先,我知道Spring Boot嵌入了Tomcat。
其次,我想从EclipseTomcat开始,而不是Spring Boot嵌入式Tomcat 谢谢 2018年9月11日
我试过了,但还是失败了。
build.gradle:
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compileOnly group: 'javax.servlet', name: 'servlet-api', version: '3.0.1'
}
Tomcat仍然找不到我的应用程序类。我认为需要将servlet类添加到web.xml中 2018年9月11日-2
格雷德尔先生
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.1.0.RELEASE'
}
testImplementation('org.springframework.boot:spring-boot-starter-test')
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}
完全排除了spring启动tomcat,我添加了servleet api。现在他们告诉我错误
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE)
2018-11-09 17:10:34.138 INFO 8712 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on DESKTOP-E0BBPVE with PID 8712 (C:\Users\knowch\eclipse-workspace\demo\bin\main started by knowch in C:\Users\knowch\eclipse-workspace\demo)
2018-11-09 17:10:34.142 INFO 8712 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-11-09 17:10:34.796 WARN 8712 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2018-11-09 17:10:34.805 INFO 8712 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-09 17:10:34.814 ERROR 8712 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.example.demo.DemoApplication.main(DemoApplication.java:17) [main/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
我的结果是他们必须找到嵌入式tomcat,而这不是选项。这是TomcatWebServer.class
/**
* Create a new {@link TomcatWebServer} instance.
* @param tomcat the underlying Tomcat server
*/
public TomcatWebServer(Tomcat tomcat) {
this(tomcat, true);
}
/**
* Create a new {@link TomcatWebServer} instance.
* @param tomcat the underlying Tomcat server
* @param autoStart if the server should be started
*/
public TomcatWebServer(Tomcat tomcat, boolean autoStart) {
Assert.notNull(tomcat, "Tomcat Server must not be null");
this.tomcat = tomcat;
this.autoStart = autoStart;
initialize();
}
在IDE工具中,我们不能使用eclipse tomcat?:(很遗憾.Spring Boot有一个内置的Tomcat,它作为Java可执行文件运行 只需右键单击plusApplication类,然后:
Run As -> Spring Boot App
或
您的类应该如下所示,Spring Boot将完成其余部分:
@SpringBootApplication
public class PlusFApplication {
public static void main(String[] args) {
SpringApplication.run(PlusFApplication.class, args);
}
}
如果您在导入并首先运行应用程序时遇到问题。您是如何运行应用程序的,是否有任何错误?Springboot默认在tomcat服务器上运行,因此您可以删除tomcat依赖项并再次运行应用程序。您能分享错误吗?如果您能分享具体内容,我将很乐意回答你错了facing@Arnaud不,没有错误。在控制台中也没有开始登录。@GauravRai1512我会的。谢谢!我没有这样的选项
Run->Spring Boot App
,如何添加它?@user7294900您的项目设置不正确,最简单的事情是将源代码作为maven项目重新导入。退出eclipse,确保您成功在再次导入之前,请删除所有旧的eclipse文件夹和文件(.project、classpath、.settings)。
@SpringBootApplication
public class PlusFApplication {
public static void main(String[] args) {
SpringApplication.run(PlusFApplication.class, args);
}
}