简体   繁体   English

无法在基本 Spring Boot 项目上启动 Tomcat 服务器

[英]Unable to start Tomcat Server on Basic Spring Boot Project

I'm beginning to learn Spring Boot and have created a sample project.我开始学习 Spring Boot 并创建了一个示例项目。 Below the Pom.xml file:在 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.khushboo.java</groupId>
    <artifactId>learning-spring</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>learning-spring</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

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

</project>

And this is the output:这是输出:

[INFO] 
[INFO] -----------------< com.khushboo.java:learning-spring >------------------
[INFO] Building learning-spring 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ learning-spring ---
[INFO] Deleting /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ learning-spring ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ learning-spring ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ learning-spring ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ learning-spring ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ learning-spring ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.khushboo.java.learningspring.LearningSpringApplicationTests
14:25:59.947 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
14:25:59.961 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
14:26:00.024 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.khushboo.java.learningspring.LearningSpringApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
14:26:00.043 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.khushboo.java.learningspring.LearningSpringApplicationTests], using SpringBootContextLoader
14:26:00.050 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.khushboo.java.learningspring.LearningSpringApplicationTests]: class path resource [com/khushboo/java/learningspring/LearningSpringApplicationTests-context.xml] does not exist
14:26:00.051 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.khushboo.java.learningspring.LearningSpringApplicationTests]: class path resource [com/khushboo/java/learningspring/LearningSpringApplicationTestsContext.groovy] does not exist
14:26:00.052 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.khushboo.java.learningspring.LearningSpringApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
14:26:00.053 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.khushboo.java.learningspring.LearningSpringApplicationTests]: LearningSpringApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
14:26:00.175 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.khushboo.java.learningspring.LearningSpringApplicationTests]
14:26:00.261 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/target/classes/com/khushboo/java/learningspring/LearningSpringApplication.class]
14:26:00.263 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.khushboo.java.learningspring.LearningSpringApplication for test class com.khushboo.java.learningspring.LearningSpringApplicationTests
14:26:00.400 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.khushboo.java.learningspring.LearningSpringApplicationTests]: using defaults.
14:26:00.401 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
14:26:00.440 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
14:26:00.441 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
14:26:00.442 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4bf48f6, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@420a85c4, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@1c39680d, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@62833051, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@1c852c0f, org.springframework.test.context.support.DirtiesContextTestExecutionListener@a37aefe, org.springframework.test.context.event.EventPublishingTestExecutionListener@5d99c6b5, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@266374ef, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@13b3d178, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@24c4ddae, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@37fb0bed, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@a82c5f1, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@7b7fdc8]
14:26:00.455 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@2d9caaeb testClass = LearningSpringApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@42a15bdc testClass = LearningSpringApplicationTests, locations = '{}', classes = '{class com.khushboo.java.learningspring.LearningSpringApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@8c3b9d, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@1e178745, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@38e79ae3, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@5f8edcc5, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@3e96bacf, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@3f49dace], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.1)

2022-07-04 14:26:00.891  INFO 4633 --- [           main] c.k.j.l.LearningSpringApplicationTests   : Starting LearningSpringApplicationTests using Java 17.0.3.1 on LP-C1MR90A7G942 with PID 4633 (started by khushboo.k in /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring)
2022-07-04 14:26:00.895  INFO 4633 --- [           main] c.k.j.l.LearningSpringApplicationTests   : No active profile set, falling back to 1 default profile: "default"
2022-07-04 14:26:02.256  INFO 4633 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2022-07-04 14:26:02.549  INFO 4633 --- [           main] c.k.j.l.LearningSpringApplicationTests   : Started LearningSpringApplicationTests in 2.032 seconds (JVM running for 3.477)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.914 s - in com.khushboo.java.learningspring.LearningSpringApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ learning-spring ---
[INFO] Building jar: /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/target/learning-spring-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.7.1:repackage (repackage) @ learning-spring ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ learning-spring ---
[INFO] Installing /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/target/learning-spring-0.0.1-SNAPSHOT.jar to /Users/khushboo.k/.m2/repository/com/khushboo/java/learning-spring/0.0.1-SNAPSHOT/learning-spring-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/khushboo.k/Documents/EclipseWorkspace/learning-spring/pom.xml to /Users/khushboo.k/.m2/repository/com/khushboo/java/learning-spring/0.0.1-SNAPSHOT/learning-spring-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.469 s
[INFO] Finished at: 2022-07-04T14:26:06+05:30
[INFO] ------------------------------------------------------------------------

Why the Tomcat server is not started?为什么Tomcat服务器没有启动? I have deleted all the files inside m2 hidden folder and ran the application again.我已删除 m2 隐藏文件夹中的所有文件并再次运行该应用程序。

Below is the way I am running the project:以下是我运行项目的方式:

在此处输入图像描述

The problem is resolved.问题已解决。

I edited the Goals while running the Maven project.我在运行 Maven 项目时编辑了目标。 The Goal should be: spring-boot:run.目标应该是:spring-boot:run。 This runs the tomcat server.这将运行 tomcat 服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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