Проблема с запуском приложения basi c Spring Boot - PullRequest
0 голосов
/ 18 января 2020

Я работал над вводным Учебным пособием по Spring Boot .

Я прошел все этапы

./mvnw spring-boot:run

Из каталог проекта.

, который генерирует вывод:

Let's inspect the beans provided by Spring Boot:
application
beanNameHandlerMapping
defaultServletHandlerMapping
dispatcherServlet
embeddedServletContainerCustomizerBeanPostProcessor
handlerExceptionResolver
helloController
httpRequestHandlerAdapter
messageSource
mvcContentNegotiationManager
mvcConversionService
mvcValidator
org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$DispatcherServletConfiguration
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
org.springframework.boot.context.embedded.properties.ServerProperties
org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
propertySourcesBinder
propertySourcesPlaceholderConfigurer
requestMappingHandlerAdapter
requestMappingHandlerMapping
resourceHandlerMapping
simpleControllerHandlerAdapter
tomcatEmbeddedServletContainerFactory
viewControllerHandlerMapping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.530 s
[INFO] Finished at: 2020-01-18T14:29:53-04:00
[INFO] ------------------------------------------------------------------------

Но когда я запускаю $ curl localhost:8080 из отдельного окна терминала вместо ожидаемого:

Greetings from Spring Boot!

Я получаю: curl: (7) Failed to connect to localhost port 8080: Connection refused

Вот мой pom. xml file:

<?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.2.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

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


    </dependencies>



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

</project>

Любая помощь или понимание будут очень признательны.

Спасибо

Ответы [ 2 ]

0 голосов
/ 18 января 2020

Я попытался выполнить следующие шаги в командной строке и успешно работал:

git clone https://github.com/spring-guides/gs-spring-boot.git

после завершения клонирования будет создан новый каталог gs-spring-boot, затем измените каталог на gs-spring-boot / initial

cd gs-spring-boot/initial

, затем выполните следующую команду

./mvnw spring-boot:run

, если вы уже установили maven и доступны в вашем пути, вместо этого вы можете использовать следующую команду

mvn spring-boot:run

затем spring запуск приложения начинается после завершения весенней загрузки приложения без нажатия клавиш Ctrl + c и завершения переключения приложения на почтальона и указания адреса:

localhost:8080

, тогда вы увидите ожидаемый результат, как показано ниже

enter image description here

0 голосов
/ 18 января 2020

После копирования файла pom. xml непосредственно из учебника, я заметил, что, вероятно, есть важное отличие:

new (работает):

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

old:

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

Обратите внимание на spring-boot-start- web vs spring-boot-starter

Основано на информации из этого сообщения переполнения стека spring-boot- стартер-паутина включает в себя:

  • пружинный стартер
  • Джексон
  • пружинный сердечник
  • пружина- mvc
  • spring-boot-starter-tomcat

Изначально я использовал spring-boot-starter, а не spring-boot-starter-web, и добавил spring- mvc вручную. Скорее всего, требуются и некоторые из этих других зависимостей.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...