Я не могу сопоставить конечную точку отдыха с Spring Boot - PullRequest
0 голосов
/ 22 марта 2020

Я начинаю работу со SpringBoot в новом проекте и пытаюсь создать среду, похожую на базу.

Итак, я сопоставляю конечные точки, но когда я запускаю сервер, я видно, что эти конечные точки не загружаются.

Мой класс отдыха

@RestController
@RequestMapping("/estados")
public class EstadoResource {

@Autowired private EstadoRepository estadoRepository;

@RequestMapping(value = "/criar", method = RequestMethod.GET)
public String criar() {
    Estado estado = new Estado();

    estado.setNome("Rio de Janeiro");

    return "Rest Funcionando";
    }
}

Я пытался с @GetMapping и тоже не работал.

пом. 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>

    <groupId>com.apppet.backend</groupId>
    <artifactId>app-pet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>app-pet</name>
    <description>Aplicacao Backend Pet</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>11</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>

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

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

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

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>LATEST</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>LATEST</version>
        </dependency>


        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
        </dependency>
    </dependencies>

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

приложение. xml

spring.datasource.url=jdbc:postgresql://localhost:5432/app_pet
spring.datasource.username=app_pet
spring.datasource.password=

logging.level.web=DEBUG

spring.jpa.hibernate.ddl-auto=none

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

Основной класс

@SpringBootApplication
public class App4petApplication {

    public static void main(String[] args) {
        SpringApplication.run(App4petApplication.class, args);
    }

}

Spring Console

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

2020-03-22 00:15:17.148  INFO 12893 --- [  restartedMain] c.a.backend.apppet.ApppetApplication   : Starting ApppetApplication on gustavo-rey with PID 12893 (/home/gustavo-rey/Pet/Backend/target/classes started by gustavo-rey in /home/gustavo-rey/Pet/Backend)
2020-03-22 00:15:17.152  INFO 12893 --- [  restartedMain] c.a.backend.apppet.ApppetApplication   : No active profile set, falling back to default profiles: default
2020-03-22 00:15:17.249  INFO 12893 --- [  restartedMain] o.s.b.devtools.restart.ChangeableUrls    : The Class-Path manifest attribute in /home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/home/gustavo-rey/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2020-03-22 00:15:17.252  INFO 12893 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-03-22 00:15:18.061  INFO 12893 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-22 00:15:18.076  INFO 12893 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9ms. Found 0 JPA repository interfaces.
2020-03-22 00:15:18.591  INFO 12893 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-03-22 00:15:18.601  INFO 12893 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-22 00:15:18.602  INFO 12893 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-22 00:15:18.727  INFO 12893 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-03-22 00:15:18.727 DEBUG 12893 --- [  restartedMain] o.s.web.context.ContextLoader            : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2020-03-22 00:15:18.727  INFO 12893 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1475 ms
2020-03-22 00:15:18.746 DEBUG 12893 --- [  restartedMain] o.s.b.w.s.ServletContextInitializerBeans : Mapping filters: characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105
2020-03-22 00:15:18.747 DEBUG 12893 --- [  restartedMain] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2020-03-22 00:15:18.882  INFO 12893 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-03-22 00:15:18.932  INFO 12893 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-03-22 00:15:19.013  INFO 12893 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-03-22 00:15:19.085  INFO 12893 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-03-22 00:15:19.281  INFO 12893 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-03-22 00:15:19.298  INFO 12893 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-03-22 00:15:19.644  INFO 12893 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-03-22 00:15:19.650  INFO 12893 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-03-22 00:15:19.707  WARN 12893 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-03-22 00:15:19.830  INFO 12893 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-22 00:15:19.838 DEBUG 12893 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2020-03-22 00:15:19.875 DEBUG 12893 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2020-03-22 00:15:19.904 DEBUG 12893 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2020-03-22 00:15:19.914 DEBUG 12893 --- [  restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2020-03-22 00:15:19.996  INFO 12893 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-03-22 00:15:20.038  INFO 12893 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-22 00:15:20.041  INFO 12893 --- [  restartedMain] c.a.backend.apppet.ApppetApplication   : Started ApppetApplication in 3.853 seconds (JVM running for 5.053)

Кто-то знает, что я могу делать неправильно?

Спасибо!

Edit1: Когда я пытался получить доступ к localhost: 8080 / estados / criar показывает белую страницу прыгун с ошибкой 404

Edit2: Ребята, после некоторых тестов я был В состоянии заставить это работать, я понял, что, если я помещаю Основной Весенний Класс в тот же самый пакет Контроллеров, система сопоставляет конечные точки правильно, но я полагаю, что это не идеально, кто-то знает, как я могу настроить это?

...