【发布时间】:2019-10-30 23:02:00
【问题描述】:
我正在使用 spring boot 开发一个 web 应用程序,并且我在下面给出的 application.properties 文件中添加了上下文路径,但是当我运行应用程序时它没有使用上下文路径。
"我添加了#Context Path server.port=8085 server.servlet.context-path=/nvs-councellor in application.properties 文件"
spring.mvc.view.prefix=/WEB-INF/JSP/
spring.mvc.view.suffix=.jsp
# create and drop tables and sequences, loads import.sql
spring.jpa.hibernate.ddl-auto=update
#Turn Statastics on
spring.jpa.properties.hibernate.generate_statistics=true
logging.level.org.hibernate.stat=debug
# Show all queries
spring.jpa.show-sql=true
logging.level.org.hibernate.type=trace
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# PostgreSql settings
spring.datasource.url=jdbc:postgresql://10.226.1.10:5444/NVS_COUNSELLOR
spring.datasource.username=cefipra
spring.datasource.password=cefipra
spring.jpa.properties.hibernate.default_schema=nvs_counsellor
spring.datasource.driverClassName = org.postgresql.Driver
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
#Context Path
server.port=8085
server.servlet.context-path=/nvs-councellor
“当我使用 url http://localhost:8080/nvs-councellor/COUNSELLOR 运行应用程序时,它会显示正确的页面,但是当我执行其他操作时,它会给我 404 并带有以下 url http://localhost:8080/loginAction”
【问题讨论】:
-
既然你已经添加了上下文路径,你还必须为 api 包含它,所以 URL:
http://localhost:8080/nvs-councellor/loginAction -
@Avi- 我需要在每个请求映射中附加 /nvs-councellor 吗??
-
不,
@RequestMapping中没有,当您从 UI 或其他服务调用时,您必须包含它 -
@Avi- 但是在我正在工作的其他 Spring Boot 应用程序中,没有必要这样做。上下文路径需要自动附加到传入请求
-
对于客户你在用什么?
标签: spring-boot