gpt4 book ai didi

java - 在 spring 中将正则表达式设置为属性值

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:57:57 25 4
gpt4 key购买 nike

我需要将正则表达式设置为 spring 配置文件中的属性值。我的代码是这样的

xml文件

<property name="regex">
<value type="java.lang.String">[^&%$#@!/~]*</value>
</property>

java代码

public void setRegex(String regex) {


try {
Pattern.compile(regex);
this.regex = regex;
} catch (PatternSyntaxException exception) {
System.err.println(exception.getDescription());

}

}

但这行不通。它在运行时抛出异常。

[exec] java.lang.IllegalStateException
[exec] at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1588)
[exec] at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
[exec] at com.sun.faces.application.ConverterPropertyEditorFactory$DisposableClassLoader.loadClass(ConverterPropertyEditorFactory.java:447)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[exec] at java.lang.Class.getDeclaredConstructors0(Native Method)
[exec] at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
[exec] at java.lang.Class.getConstructor0(Class.java:3075)
[exec] at java.lang.Class.newInstance(Class.java:412)
[exec] at com.sun.beans.finder.InstanceFinder.instantiate(InstanceFinder.java:96)
[exec] at com.sun.beans.finder.PropertyEditorFinder.find(PropertyEditorFinder.java:81)
[exec] at java.beans.PropertyEditorManager.findEditor(PropertyEditorManager.java:90)
[exec] at com.sun.faces.application.ApplicationImpl.addPropertyEditorIfNecessary(ApplicationImpl.java:690)
[exec] at com.sun.faces.application.ApplicationImpl.addConverter(ApplicationImpl.java:660)
[exec] at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:727)
[exec] at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:489)
[exec] at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:381)
[exec] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
[exec] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
[exec] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
[exec] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
[exec] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
[exec] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
[exec] at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:663)
[exec] at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1642)
[exec] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[exec] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[exec] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[exec] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[exec] at java.lang.Thread.run(Thread.java:745)

完整的堆栈跟踪

最佳答案

使用你的正则表达式值,你应该得到错误

The entity name must immediately follow the '&' in the entity reference" because of '&' character

在您的 xml 中,尝试如下更改正则表达式值,看看您是否仍然收到 IllegalStateException。

<property name="regex">
<value type="java.lang.String">[^&amp;%$#@!/~]*</value>
</property>

关于java - 在 spring 中将正则表达式设置为属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32110003/

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