幾天前我看過 Stack Overflow。我的問題似乎很常見,但我無法解決。我試過這些方法1和2。這是我的 application.propreties :spring.datasource.driver-class-name= org.postgresql.Driverspring.datasource.url=jdbc:postgresql://localhost:5433/mydatabasespring.datasource.username=usernamespring.datasource.password=passwordspring.jpa.hibernate.ddl-auto=createspring.main.web-application-type=none當(dāng)我嘗試運行它時,它給了我以下錯誤: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這些是我的主要課程:@SpringBootApplicationpublic class StartApplication { @Autowired BookRepository repository; public static void main(String[] args) { SpringApplication.run(Application.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>toto</groupId> <artifactId>toto</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> </dependency>在此先感謝您的幫助。
3 回答

牛魔王的故事
TA貢獻1830條經(jīng)驗 獲得超3個贊
你的主類應(yīng)該是這樣的:
@SpringBootApplication
public class StartApplication {
@Autowired
BookRepository repository;
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
}

呼如林
TA貢獻1798條經(jīng)驗 獲得超3個贊
您應(yīng)該從 application.properties 文件中刪除以下屬性
spring.main.web-application-type=none
這意味著您的應(yīng)用程序中不需要 Web 服務(wù)器。

慕碼人8056858
TA貢獻1803條經(jīng)驗 獲得超6個贊
我不是專業(yè)程序員,但如果我是你我會怎么做:
確保你有一個合適的項目結(jié)構(gòu)
查看Spring.io的基本配置指南!
祝好運并玩得開心點 :)
添加回答
舉報
0/150
提交
取消