- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 PropertyPlaceholderConfigurer 加载属性文件中的一些变量,但它不起作用。互联网上的一些网站建议当 spring aop 不在类路径中时会出现问题,但我确保 aop 框架在我的项目中。这是我的 springContext.xml:
<!-- Register all placeholder locations -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="order" value="0" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>file:/mypath/file.properties</value>
</list>
</property>
</bean>
<!-- Register all placeholder locations -->
<password-decrypter order="10" id="passwordConfigurer">
<decrypter algorithm="PBEWithSHAAnd128BitRC4" key="${Encryption.key}" />
<decryption-entries>
<decryption-entry bean-ref="ds" properties="password" />
</decryption-entries>
</password-decrypter>
这是抛出错误:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'password-decrypter'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3182)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1927)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:351)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:280)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
在容器外部运行程序以将 PropertyPlaceholderConfigurer 与 ClassPathXmlApplicationContext 结合使用时,我是否需要做一些不同的事情?
最佳答案
还有一种替代方法。你可以按照下面提到的方法尝试一下。
不要在 applicationContext.xml 中定义 PropertyPlaceholderConfigurer,而是使用以下代码在 ServletContextListener 中定义它
PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
ResourceLoader resourceLoader = new DefaultResourceLoader();
Resource resource = resourceLoader.getResource("classpath:localDB.properties");
configurer.setLocation(resource);
configurer.postProcessBeanFactory(beanFactory);
这里的beanFactory是一个使用ClassPathResource创建的XmlBeanFactory。
属性文件 localDB.properties 可以包含适当的值,并且它们可以在 applicationContext.xml 中用作 ${Encryption.key},这里 Encryption.key 是来自属性文件
关于java - PropertyPlaceholderConfigurer 不适用于 ClassPathXmlApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030420/
我通过听来学习 Java Spring Framework“Spring & Hibernate for Beginners”udemy 类(class)。我在尝试时挣扎导入org.springfra
我的主类的静态方法中有以下代码 - appContext = new ClassPathXmlApplicationContext(new String[] { "classp
我将 spring 与其他框架一起使用,并且我是序列化领域的新手。 问题是什么: 我需要序列化包含 org.eclipse.jetty.websocket.api.Session session (不
我正在使用 spring hibernate maven 项目。这里我得到了异常 dispatcher-servlet.xml 文件未找到。我应该如何添加路径。或者我应该在 .classpath 文件
我有这个代码... public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApp
“本地文件名”是指资源文件与类文件位于同一目录中。在下面的例子中,这是 JUnitRunner.class 文件。 Java 的 getResource()如果路径不是以 /' 开头,文件可以处理这个
我是 Spring 新手。我在将类路径作为 ClassPathXmlApplicationContext 的参数时遇到问题。我使用 Netbeans。我使用 ClassPathXmlApplicati
我正在使用 Intellij,我的源类是 main.com.coding,我的资源文件是 main.com.testing。我将 spring.xml 文件放入资源文件中。 我的测试类位于 test.
我正在尝试使用 Spring 3.2.0 创建连接,但出现 NullPointerException: ApplicationContext ctx = new ClassPathXmlApplica
我正在使用 spring-framework 和 hibernate 开发一个 Maven 项目。我有这两种方法: public void loadXml() throws IOException,
我们有一个不在 Web 容器中运行的应用程序,所以我正在尝试启动 Spring。在“main”函数中我们有这样的: public static void main(String[] args) thr
我尝试使用 PropertyPlaceholderConfigurer 加载属性文件中的一些变量,但它不起作用。互联网上的一些网站建议当 spring aop 不在类路径中时会出现问题,但我确保 ao
我的网络应用程序使用 iText 动态创建 PDF。 GlassFish 线程池用于在单独的线程中处理每个 PDF。 Spring 遍布整个应用程序以进行依赖注入(inject)。应用程序的所有模块都
尝试使用 Spring 。 xml文件在src下。我已经搜索过,但找不到问题所在。似乎找不到 xml 文件。 我收到以下错误: Exception in thread "main" java.
我阅读了几篇有关此问题的文章,但仍然不明白如何解决我的问题。我正在使用此源作为起点创建一个 Spring Web 服务: http://eggsylife.co.uk/2010/01/03/sprin
我使用Springframework的ClassPathXMLApplicationContext来初始化一些bean,如下所示: ctx = new ClassPathXMLApplicatio
这个问题已经有答案了: BeanFactory vs ApplicationContext (22 个回答) 已关闭 8 年前。 以下两条语句显然都是用于加载 xml 配置,但它们之间有什么区别? A
这个问题已经有答案了: What causes and what are the differences between NoClassDefFoundError and ClassNotFoundE
我的代码使用以下代码实例化一个 spring 实例: String filePath = "applicationContext.xml"; ApplicationContext context =
我在使用Springs框架时遇到了一个问题,导致服务器和数据库之间无法通信。 我创建的项目是Spring项目,然后重构为Maven。 在代码中的这一行:ClassPathXmlApplicationC
我是一名优秀的程序员,十分优秀!