Spring boot 使用OAuth2启动spring引导时发生org.springframework.beans.beans异常
我试图使用spring boot 1.3.0.RC1和Oauth2构建我自己的rest服务应用程序,并从JHipster复制为Oauth2配置生成的相同代码,此异常显示:Spring boot 使用OAuth2启动spring引导时发生org.springframework.beans.beans异常,spring-boot,oauth-2.0,jhipster,Spring Boot,Oauth 2.0,Jhipster,我试图使用spring boot 1.3.0.RC1和Oauth2构建我自己的rest服务应用程序,并从JHipster复制为Oauth2配置生成的相同代码,此异常显示: Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [hello.OAuth2ServerConfiguration$$EnhancerBySpringCGL IB$$d4b42265]: No defau
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
我不能添加默认构造函数,因为数据源是最终的。请帮我弄清楚原因,谢谢。
我使用了@postConstruct init(),但仍然不起作用。您使用的是哪个版本的Spring Boot?配置类的构造函数注入仅支持Spring Boot 1.4及更高版本(这是Spring Framework 4.3的一个新功能)。非常感谢,@AndyWilkinson,我使用的是Spring Boot 1.3.0.RC1,升级到1.4.3版本后,异常消失了。
@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