gpt4 book ai didi

java - Spring MVC : adding securityConfig. xml 以及dispatcherContext.xml

转载 作者:行者123 更新时间:2023-12-01 12:50:42 25 4
gpt4 key购买 nike

我在 web.xml 中遇到了这段代码,但我不明白如何添加 securityConfig.xmldispatcherContext.xml 一起添加到类路径

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcherContext.xml</param-value>
</context-param>

谁能给我一些建议

更新

当我包括<import resource="classpath:securityConfig.xml" />时在dispatcherContext.xml如下图所示

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<import resource="classpath:securityConfig.xml" />

我收到以下异常

ContextLoader - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:securityConfig.xml]
Offending resource: class path resource [dispatcherContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [securityConfig.xml]; nested exception is java.io.FileNotFoundException: class path resource [securityConfig.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

最佳答案

只需在根上下文定义(在您的情况下是dispatcherContext.xml)文件中使用导入:

<!-- Load spring security related configuration -->
<import resource="classpath:securityConfig.xml"/>

但是您可以通过在文件名之间添加空格来提供多个:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>dispatcherContext.xml securityConfig.xml</param-value>
</context-param>

关于java - Spring MVC : adding securityConfig. xml 以及dispatcherContext.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24232298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com