spring注入失败 使用junit测试dao层的时候显示找不到匹配的类

applicationContext的配置
<context:component-scan base-package="com"
annotation-config="true">
<context:include-filter type="regex"
expression=".Actions.*" />
<context:include-filter type="regex"
expression=".Server.*" />
<context:include-filter type="regex"
expression=".Dao.*" />
</context:component-scan>
<context:annotation-config />

dao层
import com.trionfo.freenat.model.User;

public interface UserDao {

impl层
@Component
public class UserDaoImpl implements UserDao

你的include-filter是使用的正则,看起来你的正则好像有问题,你可以改成如下试一下:

<context:component-scan base-package="com"
annotation-config="true">
<context:include-filter type="regex"
expression=".*\.Actions.*" />
<context:include-filter type="regex"
expression=".*\.Server.*" />
<context:include-filter type="regex"
expression=".*\.Dao.*" />
</context:component-scan>
<context:annotation-config />

或者是:expression="包路径.Actions.*"



Spring对此处处理的原码如下:

public class RegexPatternTypeFilter extends AbstractClassTestingTypeFilter {

private final Pattern pattern;

public RegexPatternTypeFilter(Pattern pattern) {
Assert.notNull(pattern, "Pattern must not be null");
this.pattern = pattern;
}

@Override
protected boolean match(ClassMetadata metadata) {
return this.pattern.matcher(metadata.getClassName()).matches();
}

}

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网