下面是beans.xml文件的摘錄:Spring XML和java.util.regex.Pattern.compile ...不工作?
<bean class="java.util.regex.Pattern" factory-method="compile">
<constructor-arg value=".*some pattern.*"/>
<constructor-arg type="int" value="{ T(java.util.regex.Pattern).DOTALL | T(java.util.regex.Pattern).CASE_INSENSITIVE }"/>
</bean>
對於未知reasing我收到以下錯誤,而Spring框架加載:
2015-10-01 00:05:14 WARN XmlWebApplicationContext:487 - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.FilterFactoryBean#4': Cannot create inner bean com.test.test_core.monitor.DocumentFieldRegexFilter#0' of type [com.test.test_core.monitor.DocumentFieldRegexFilter] while setting bean property 'targetObject'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.test.test_core.monitor.DocumentFieldRegexFilter#0#1' defined in file [c:\java\jetty\config\dev\spring-context\local-beans-1.xml]: Cannot create inner bean 'util:list#719d35e8' of type [org.springframework.beans.factory.config.ListFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'util:list#719d35e8': Cannot create inner bean 'org.apache.commons.lang3.tuple.Pair#244e619a' of type [org.apache.commons.lang3.tuple.Pair] while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.commons.lang3.tuple.Pair#244e619a' defined in file [c:\java\jetty\config\dev\spring-context\local-beans-1.xml]: Cannot create inner bean 'java.util.regex.Pattern#10ef5fa0' of type [java.util.regex.Pattern] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'java.util.regex.Pattern#10ef5fa0' defined in file [c:\java\jetty\config\dev\spring-context\local-beans-1.xml]: No matching factory method found: factory method 'compile(String,int)'. Check that a method with the specified name and arguments exists and that it is static.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477)
我不明白爲什麼我得到這個錯誤:
No matching factory method found: factory method 'compile(String,int)'
如果恰好有根據http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
這樣的方法我使用Windows 7,Java版本:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
任何想法?
編輯:
我找到了解決辦法 - 遊戲是不正確的。我改變了按比例或簡單地加上和它的工作(我知道,它是不一樣的,但這是一個不同的故事)。此外,我需要在開始處添加#(hashtag),但根據Spring文檔,它不是必需的:
<bean class="java.util.regex.Pattern" factory-method="compile">
<constructor-arg value=".*some pattern.*"/>
<constructor-arg type="int" value="#{ T(java.util.regex.Pattern).DOTALL + T(java.util.regex.Pattern).CASE_INSENSITIVE }"/>
</bean>
不要編輯您的問題並在其中添加答案。如果你覺得有必要,你應該在該代碼中添加一個答案。然後你可以接受相應的答案。 – Tunaki