我一直试图在2.1.0版本中运行spring boot。即使尝试访问localhost:8080,我也收到404错误。我已经修改了所有控制器,并在同一主程序包中服务,但是没有运气。任何帮助表示赞赏。下面是我的控制台日志。即使localhost:8080也无法正常工作。
<pre>
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.1.0.RELEASE:run (default-cli) > test-compile @ demo >>>
[WARNING] The POM for ojdbc:ojdbc:jar:6 is missing, no dependency information available
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\demo\demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ demo ---
[INFO] No sources to compile
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.1.0.RELEASE:run (default-cli) < test-compile @ demo <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.1.0.RELEASE:run (default-cli) @ demo ---
Spring Boot :: (v2.1.0.RELEASE)
2018-11-01 16:56:39.864 INFO 13552 --- [ main] com.DemoApplication : Starting DemoApplication on (C:\demo\demo\target\classes started by mine in C:\demo\demo)
2018-11-01 16:56:39.872 INFO 13552 --- [ main] com.DemoApplication : No active profile set, falling back to default profiles: default
2018-11-01 16:56:41.492 INFO 13552 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2018-11-01 16:56:41.666 INFO 13552 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 159ms. Found 1 repository interfaces.
2018-11-01 16:56:42.989 INFO 13552 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-11-01 16:56:43.069 INFO 13552 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-11-01 16:56:43.070 INFO 13552 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.12
2018-11-01 16:56:43.096 INFO 13552 --- [ 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_131\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_144/bin/server;C:/Program Files/Java/jre1.8.0_144/bin;C:/Program Files/Java/jre1.8.0_144/lib/amd64;C:\app\mine\product\11.2.0\client_1\bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\app\mine\product\11.2.0\client_1;C:\Program Files\Java\jdk1.8.0_131\bin;C:\Software\apache-maven-3.5.2-bin\apache-maven-3.5.2\bin;C:\ProgramData\Oracle\Java\javapath;C:\app\mine\product\11.2.0\client\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Symantec\Workspace Streaming\bin\;C:\Program Files\Symantec\Workspace Virtualization\;C:\Program Files\TortoiseSVN\bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Program Files\1E\NomadBranch\;C:\Program Files\Common Files\ThinPrint\;C:\Program Files\nodejs\;C:\Users\mine\AppData\Roaming\npm;C:\Windows\system32;;.]
2018-11-01 16:56:43.402 INFO 13552 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/h] : Initializing Spring embedded WebApplicationContext
2018-11-01 16:56:43.402 INFO 13552 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3419 ms
2018-11-01 16:56:43.496 INFO 13552 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-11-01 16:56:43.916 INFO 13552 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-11-01 16:56:45.002 INFO 13552 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
2018-11-01 16:56:45.040 INFO 13552 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-11-01 16:56:45.189 INFO 13552 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-11-01 16:56:45.371 INFO 13552 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
2018-11-01 16:56:45.375 INFO 13552 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-11-01 16:56:45.791 INFO 13552 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2018-11-01 16:56:46.235 INFO 13552 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
2018-11-01 16:56:49.137 INFO 13552 --- [ main] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2018-11-01 16:56:49.314 INFO 13552 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-11-01 16:56:50.878 INFO 13552 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/h'
2018-11-01 16:56:50.881 INFO 13552 --- [ main] com.DemoApplication : Started DemoApplication in 13.048 seconds (JVM running for 25.664)
</pre>
**Main class:**
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
控制器类:
@RestController
public class MobilityApi {
@Autowired
private MobilityService mobilityService;
@RequestMapping(method=RequestMethod.GET,value="/mobilityCC")
public Response retrieveOrderDetails(@QueryParam("orderid") String orderid) {
return mobilityService.getOrderDetails(orderid);
}
答案 0 :(得分:2)
似乎Spring没有读取您的Controller,这似乎是一个结构问题。 请考虑进行以下更改:
@RestController
@RequestMapping("/your_decide/")
public class MobilityApi {
@Autowired
private MobilityService mobilityService;
@GetMapping("/mobilityCC")
public Response retrieveOrderDetails(@RequestParam("orderid") String orderid) {
return mobilityService.getOrderDetails(orderid);
}
}
要消耗其余端点,请尝试访问localhost:8080/your_decide/mobilityCC
编辑:
确保您具有spring-web依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>