【问题标题】:Context Path is not working in spring boot上下文路径在 Spring Boot 中不起作用
【发布时间】: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


【解决方案1】:

@Shubham Gadekar - 只需从您调用任何操作或 href 的位置删除 / 例如 - action="loginAction" 代替 action="/loginAction" 它对我有用,所以请在你的最后尝试。谢谢。

【讨论】:

    猜你喜欢
    • 2018-07-04
    • 2021-02-17
    • 1970-01-01
    • 2021-11-10
    • 2017-03-03
    • 2021-06-07
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多