【问题标题】:How to import spring configuration?如何导入弹簧配置?
【发布时间】:2013-10-10 10:31:13
【问题描述】:

我有这个项目结构:

我能写什么@ContextConfiguration(locations = { "what I must write here?" }) 成功导入?

【问题讨论】:

    标签: java spring spring-security


    【解决方案1】:
    @ContextConfiguration("file:src/main/webapp/WEB-INF/spring/spring_config.xml")
    

    Location of spring-context.xml

    您还可以将文件移动到 resources 文件夹:

    您可以将 Spring 配置文件存储在类路径中(例如,src/main/resources),然后通过类路径引用它们。

    @ContextConfiguration("classpath:/WEB-INF/spring/spring_config.xml")
    

    【讨论】:

    • 忽略我之前的评论 - 这很好。把 @ContextConfiguration 和别的东西混在一起了,忘了它只在测试上下文中使用。
    • 课程?你确定吗?
    【解决方案2】:

    首先,您需要将webapp 添加为源文件夹,以便WEB-INF 在类路径的顶部可用(就像在部署的应用程序中一样)。然后你可以使用/WEB-INF/spring/security_config.xml

    另外,有些人更喜欢将他们的 XML 文件放在 src/main/resources 中。

    【讨论】:

      猜你喜欢
      • 2011-09-11
      • 2019-09-26
      • 2015-01-08
      • 2023-02-15
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      相关资源
      最近更新 更多