使用OAuth2启动spring引导时的org.springframework.beans.BeanInstantiationException

时间:2017-03-19 14:25:54

标签: spring-boot oauth-2.0 jhipster

我试图使用spring-boot 1.3.0.RC1和Oauth2来构建我自己的休息服务应用程序,并从JHipster复制相同的OAuth2 configuraiton生成代码,此例外显示:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [hello.OAuth2ServerConfiguration$$EnhancerBySpringCGL
IB$$d4b42265]: No default constructor found; nested exception is java.lang.NoSuchMethodException: hello.OAuth2ServerConfiguration$$EnhancerB
ySpringCGLIB$$d4b42265.<init>()
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.j
ava:1098)
        ... 23 more
Caused by: java.lang.NoSuchMethodException: hello.OAuth2ServerConfiguration$$EnhancerBySpringCGLIB$$d4b42265.<init>()
        at java.lang.Class.getConstructor0(Class.java:3082)
        at java.lang.Class.getDeclaredConstructor(Class.java:2178)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
        ... 24 more

我的代码是:

@Configuration
public class OAuth2ServerConfiguration {

    private static final String RESOURCE_ID = "restservice";

    private final DataSource dataSource;

    public OAuth2ServerConfiguration(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Bean
    public JdbcTokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    } ...some other code

我无法添加默认构造函数,因为DataSource是最终的。请帮我理解,谢谢。 我使用@postConstruct init(),仍然无法正常工作。

0 个答案:

没有答案