spring注入失败 使用junit测试dao层的时候显示找不到匹配的类
applicationContext的配置<context:component-scanbase-package="com"annotation-config="true...
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 展开
<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 展开
1个回答
展开全部
你的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();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询