spring集成中的Bean定义
我是春天的新手。我想为下面的代码编写一个bean定义spring集成中的Bean定义,spring,Spring,我是春天的新手。我想为下面的代码编写一个bean定义 package com.abc.common.filter; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.log4j.Logger; public class RegexFilter implements Filter<String> { Logger logger = Logger.getLogg
package com.abc.common.filter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
public class RegexFilter implements Filter<String> {
Logger logger = Logger.getLogger(RegexFilter.class);
private Pattern regex;
private String lastMatch;
public RegexFilter(String regexString) {
this.lastMatch = null;
regex = Pattern.compile(regexString, Pattern.UNICODE_CHARACTER_CLASS);
}
@Override
public boolean matches(String text) {
text = text.toLowerCase();
if (text == null) {
logger.error("No text set for matching!");
return false;
}
Matcher matcher = regex.matcher(text);
if (matcher.find(0)) {// always start at index 0
this.lastMatch = matcher.group();
if (logger.isDebugEnabled()) {
logger.debug(matcher.group() + " found!");
}
return true;
}
return false;
}
public String getLastMatch(){
return this.lastMatch;
}
}
package com.abc.common.filter;
导入java.util.regex.Matcher;
导入java.util.regex.Pattern;
导入org.apache.log4j.Logger;
公共类RegexFilter实现过滤器{
Logger Logger=Logger.getLogger(RegexFilter.class);
私有模式正则表达式;
私有字符串匹配;
公共RegexFilter(字符串regexString){
this.lastMatch=null;
regex=Pattern.compile(regexString,Pattern.UNICODE\u CHARACTER\u类);
}
@凌驾
公共布尔匹配(字符串文本){
text=text.toLowerCase();
if(text==null){
logger.error(“没有匹配的文本集!”);
返回false;
}
Matcher Matcher=regex.Matcher(文本);
如果(matcher.find(0)){//始终从索引0开始
this.lastMatch=matcher.group();
if(logger.isDebugEnabled()){
logger.debug(matcher.group()+“found!”);
}
返回true;
}
返回false;
}
公共字符串getLastMatch(){
返回此.lastMatch;
}
}
我被困在这一行后,我不知道如何包括索引或名称?稍微澄清一下索引和值会更有帮助
<bean id="regexfilter" class="com.abc.common.filter.RegexFilter" />
<constructor-arg name="regexString" />
</bean>
您可以定义bean
<bean id="regexfilter" class="com.abc.common.filter.RegexFilter" />
<constructor-arg type="java.lang.String" value="valueforregexstring"/>
</bean>
您可以在这里看到关于bean定义的更多信息
在使用纯java的基于注释的manor中,您可以执行以下操作:
@Configuration
public class ApplicationConfig {
@Bean
public Filter regexFilter() {
return new RegexFilter("value_for_the_regex_filter");
}
}
或者简单地说:
@Service
public class RegexFilter implements Filter<String> {
...
}
@服务
公共类RegexFilter实现过滤器{
...
}
您遇到了什么错误?或者你哪里有麻烦?