Spring 启动端点路径
Spring boot endpoint path
我的 IntelliJ 项目有一些问题。我正在尝试使用 Postman 达到终点,但我什至不知道这样做的路径是什么!我尝试了所有可能的路径,但没有任何效果!刚刚获得 404 状态。
这是我的 restController:
@RestController
@RequestMapping("/cities")
public class CityService extends GenericService<City> {
@Autowired
private CityRepository cityRepository;
/**
* Method that returns all the cities.
* @return {@link List<City>}
*/
@Override
@RequestMapping(method = RequestMethod.GET)
public List<City> loadAll(){
System.out.println(new Date() + " Called LOAD-ALL.");
return cityRepository.findAll();
}
}
我的通用服务:
public class GenericService<T> {
@Autowired
GenericRepository<T> genericRepository;
public GenericRepository<T> getGenericRepository(){
return genericRepository;
}
/**
* Method that returns all the generic entities.
* @return {@link List<T>}
*/
@GetMapping
@RequestMapping(method = RequestMethod.GET)
public List<T> loadAll(){
System.out.println(new Date() + " Called LOAD-ALL.");
return getGenericRepository().findAll();
}
我的config.properties:
spring.application.name = authorization-service
server.servlet.context-path = /authorization/api
#server.context-path = /authorization/api
#server.contextPath = /authorization/api
#server.module-path=/
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.ddl = true
spring.jpa.show-sql = true
hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
server.port = 8787
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}
eureka.instance.instance.instance-id = ${spring.application.name}:${server.port}:${random.int}
spring.cloud.loadbalancer.ribbon.enabled = false
spring.datasource.url = jdbc:mysql://localhost:3306/my_database?
createDatabaseIfNotExist=true
spring.datasource.username = someUser
spring.datasource.password = somePass
我试图在 Postman http://localhost:8787/authorization/api/cities 上使用这个 link 但没有任何效果。
有人可以帮我吗?我对映射端点这件事有点陌生。
我正在使用 Spring Boot 2.2.2.RELEASE。
启动消息是
2020-01-18 09:06:10.023 INFO 2808 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8787 (http) with context path '/authorization/api'
请尝试 属性。
server.servlet.context-path = /authorization/api
此外,当 spring 启动应用程序启动时,上下文路径将显示在日志中,如下所示
[2m2020-01-18 08:41:04.513[0;39m [32m INFO[0;39m [35m13986[0;39m
[2m---[0;39m [2m[ main][0;39m
[36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m
Tomcat started on port(s): 8080 (http) with context path
'/authorization/api'
还有以下
@GetMapping
@RequestMapping(method = RequestMethod.GET, value = "")
意思相同。请检查 @GetMapping
更新
Op 在组件扫描和控制器 类 方面存在问题未被自动检测到。
我的 IntelliJ 项目有一些问题。我正在尝试使用 Postman 达到终点,但我什至不知道这样做的路径是什么!我尝试了所有可能的路径,但没有任何效果!刚刚获得 404 状态。 这是我的 restController:
@RestController
@RequestMapping("/cities")
public class CityService extends GenericService<City> {
@Autowired
private CityRepository cityRepository;
/**
* Method that returns all the cities.
* @return {@link List<City>}
*/
@Override
@RequestMapping(method = RequestMethod.GET)
public List<City> loadAll(){
System.out.println(new Date() + " Called LOAD-ALL.");
return cityRepository.findAll();
}
}
我的通用服务:
public class GenericService<T> {
@Autowired
GenericRepository<T> genericRepository;
public GenericRepository<T> getGenericRepository(){
return genericRepository;
}
/**
* Method that returns all the generic entities.
* @return {@link List<T>}
*/
@GetMapping
@RequestMapping(method = RequestMethod.GET)
public List<T> loadAll(){
System.out.println(new Date() + " Called LOAD-ALL.");
return getGenericRepository().findAll();
}
我的config.properties:
spring.application.name = authorization-service
server.servlet.context-path = /authorization/api
#server.context-path = /authorization/api
#server.contextPath = /authorization/api
#server.module-path=/
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.ddl = true
spring.jpa.show-sql = true
hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
server.port = 8787
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}
eureka.instance.instance.instance-id = ${spring.application.name}:${server.port}:${random.int}
spring.cloud.loadbalancer.ribbon.enabled = false
spring.datasource.url = jdbc:mysql://localhost:3306/my_database?
createDatabaseIfNotExist=true
spring.datasource.username = someUser
spring.datasource.password = somePass
我试图在 Postman http://localhost:8787/authorization/api/cities 上使用这个 link 但没有任何效果。 有人可以帮我吗?我对映射端点这件事有点陌生。 我正在使用 Spring Boot 2.2.2.RELEASE。 启动消息是
2020-01-18 09:06:10.023 INFO 2808 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8787 (http) with context path '/authorization/api'
请尝试 属性。
server.servlet.context-path = /authorization/api
此外,当 spring 启动应用程序启动时,上下文路径将显示在日志中,如下所示
[2m2020-01-18 08:41:04.513[0;39m [32m INFO[0;39m [35m13986[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http) with context path '/authorization/api'
还有以下
@GetMapping
@RequestMapping(method = RequestMethod.GET, value = "")
意思相同。请检查 @GetMapping
更新 Op 在组件扫描和控制器 类 方面存在问题未被自动检测到。