Java 404RESTAPI与springboot
我在这方面已经有几天的时间了,虽然我知道他们可能会看到问题的标题被重复,但事实是,我已经尝试了几种对其他人有效但对我无效的解决方案。最有可能的事情是,这真的很愚蠢,我还没有看到它,但我的边缘 这是我的pom.xmlJava 404RESTAPI与springboot,java,rest,api,spring-boot,microservices,Java,Rest,Api,Spring Boot,Microservices,我在这方面已经有几天的时间了,虽然我知道他们可能会看到问题的标题被重复,但事实是,我已经尝试了几种对其他人有效但对我无效的解决方案。最有可能的事情是,这真的很愚蠢,我还没有看到它,但我的边缘 这是我的pom.xml <?xml version="1.0" encoding="UTF-8"?> 这是我的财产 spring.datasource.username=test spring.datasource.password=test spring.datasource.driver-
<?xml version="1.0" encoding="UTF-8"?>
这是我的财产
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url=jdbc:mysql://localhost:3306/test_avantrip?verifyServerCertificate=false&useSSL=false&requireSSL=false
server.port=8083
spring.profiles.active=@spring.profiles.active@
我收到的唯一信息是:
有什么建议吗
更新
还没有
更新2
我更改了端口,将其从.properties中删除,并将其保留在8080中,没有看到任何更改。此外,这里还有启动spring引导控制台时的消息
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
2018-12-05 14:07:29.519 INFO 1844 --- [ main] ar.com.paises.PaisesApplication : Starting PaisesApplication on MIETURAW10 with PID 1844 (D:\Proyectos\avantrip\paises\target\classes started by mietura in D:\Proyectos\avantrip\paises)
2018-12-05 14:07:29.525 INFO 1844 --- [ main] ar.com.paises.PaisesApplication : No active profile set, falling back to default profiles: default
2018-12-05 14:07:30.161 INFO 1844 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2018-12-05 14:07:30.182 INFO 1844 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 repository interfaces.
2018-12-05 14:07:30.734 INFO 1844 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-12-05 14:07:30.764 INFO 1844 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-05 14:07:30.764 INFO 1844 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2018-12-05 14:07:30.772 INFO 1844 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Intel\iCLS Client\;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_161\bin;C:\apache-maven-3.5.3\\bin;C:\apache-maven-3.5.3\\bin;C:\gradle-4.0.1\bin;C:\Users\Etura Maria Ines\AppData\Local\Android\android-sdk\platform-tools;C:\Users\Etura Maria Ines\AppData\Local\Android\android-sdk\tools;C:\Program Files\TortoiseSVN\bin;C:\Program Files\nodejs\;C:\Users\Etura Maria Ines\AppData\Local\Android\android-sdk\;8080;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\apache-ant-1.6.2\bin;C:\Program Files\PowerShell\6.0.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Users\mietura\AppData\Local\Microsoft\WindowsApps;;.]
2018-12-05 14:07:31.138 INFO 1844 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-12-05 14:07:31.138 INFO 1844 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1549 ms
2018-12-05 14:07:31.310 INFO 1844 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-12-05 14:07:31.502 INFO 1844 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-12-05 14:07:31.546 INFO 1844 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-12-05 14:07:31.609 INFO 1844 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
2018-12-05 14:07:31.613 INFO 1844 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-12-05 14:07:31.875 INFO 1844 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2018-12-05 14:07:31.986 INFO 1844 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-12-05 14:07:32.185 INFO 1844 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-12-05 14:07:32.440 INFO 1844 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-12-05 14:07:32.444 INFO 1844 --- [ main] ar.com.paises.PaisesApplication
尝试删除属性spring.profiles.active=@spring.profiles.active@将
@RequestMapping(“/”
移动到控制器类,类似于:
@RestController
public class Controls {
@RequestMapping("/")
public String home() {
return "Hello World!";
}
}
因此,您的主要方法如下所示:
@SpringBootApplication
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
}
如果查看控制台日志,您将不会看到路径“/hi”没有被映射,这意味着spring无法找到您的控制器bean 映射路径时,您应该会在中看到如下内容
RequestMappingHandlerMapping : Mapped "{[/hi],methods=[GET]}".
请将rest控制器移动到它自己的类,它可以在同一个文件中,但可以移动到一个新的不同类,如下所示:
package ar.com.paises;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
}
@RestController
class HiController {
@RequestMapping("/hi")
String home() {
return "Hello World!";
}
}
此外,请确保在部署应用程序时,会显示上一个日志
根据端口调用端点的方式应为:
检查您的端口,并将文本/普通标题添加为响应类型Spring在接收请求时是否记录了任何内容?@mumpitz No,这是not@AlmasAbdrazak端口是正确的我通过控制台验证过,我更新了我的问题,因为我在TEXT_PLAIN_值中添加了响应类型,但它仍然无法识别,可能还有其他原因。您是否检查了spring引导上下文加载是否成功并启动了tomcat服务器?与数据源相关的配置是否有效?
@SpringBootApplication
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
}
RequestMappingHandlerMapping : Mapped "{[/hi],methods=[GET]}".
package ar.com.paises;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
}
@RestController
class HiController {
@RequestMapping("/hi")
String home() {
return "Hello World!";
}
}