@Configuration注释导致IllegalArgumentException“不是增强类”

时间:2016-06-20 03:41:18

标签: spring spring-mvc

我是Spring的新手,我正在Jetty容器中使用旧的3.2.4.RELEASE版本。当我尝试使用component-scanner表示我设置的@Configuration类不是增强类时,我得到一个相当奇怪的错误:

Caused by: java.lang.IllegalArgumentException: class com.datasource.DBConfiguration$$EnhancerByCGLIB$$8a295c55 is not an enhanced class
at org.springframework.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:621) ~[spring-core-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.cglib.proxy.Enhancer.registerStaticCallbacks(Enhancer.java:594) ~[spring-core-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:120) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:92) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:356) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
... 78 common frames omitted

我的spring beans文件位于类路径中,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<context:component-scan base-package="com.datasource" /></beans>

我正在尝试设置的配置类如下所示:

@Configuration
public class DBConfiguration {

    @Bean
    public DataAccessInterface getDataAccessInterface(){
        return new DBDatasource();
    }
}

我想要将DBDatasource注入的类如下所示:

@Service
public class DBService {

    private DataAccessInterface dai;

    @Autowired
    public DBService(DataAccessInterface dai){
        this.dai = dai;
    }
}

当它说它不是增强类时,异常是什么意思?我没有正确使用组件扫描和配置注释吗?

1 个答案:

答案 0 :(得分:0)

请包括
@ComponentScan(basePackages = "com.example", includeFilters = {@Filter(filterType = ANNOTATION, value = CONFIGURATION)}, excludeFilters = {@Filter(filterType = ASSIGNABLE_TYPE, value = DBConfiguration)})

相关问题