我正在使用Spring Boot 1.3.5.RELEASE& Spring Cloud Brixton BR7使用带有JPA Repository的数据库创建具有TokenStore的OAuth服务器。 他们工作得很好!
今天我升级到Spring Boot 1.4.3.RELEASE& Spring Clound Camden SR3和我无法启动Spring启动应用程序。
似乎Auth Server配置类在JPA Repository config之前运行。
你有什么想法吗?非常感谢你。
我的AuthorizationServerConfig看起来像:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(final ClientDetailsServiceConfigurer clients) throws Exception {// @formatter:off
clients
.jdbc(dataSource()) ;
} // @formatter:on
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore())
.authenticationManager(authenticationManager)
.userDetailsService(userService);
// @formatter:on
}
@Autowired
private UserDetailsService userService;
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
// JDBC token store configuration
@Bean
@ConfigurationProperties(prefix = "oauth2.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource());
}
}
UserDetailsService看起来像
@Service("userService")
@Transactional
public class UserServiceImpl implements UserDetailsService {
@Autowired
private UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
logger.debug("Finding User by username: " + username);
User user = userRepository.findByUsername(username);
...
return new DefaultUserDetails(user);
}
}
例外是
2016-12-26 17:41:10.691 INFO 1156 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-12-26 17:41:10.868 WARN 1156 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AuthorizationServerConfig': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#503c3100' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#503c3100': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'entityManagerFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
2016-12-26 17:41:10.874 INFO 1156 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service Tomcat
2016-12-26 17:41:11.140 WARN 1156 --- [ restartedMain] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]: Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException)
2016-12-26 17:41:11.149 ERROR 1156 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
申请失败
说明
应用程序上下文中某些bean的依赖关系形成一个循环:
|
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
↑ ↓
| OAuth2ServerConfig (field private org.springframework.security.core.userdetails.UserDetailsService com.oauthserver.config.AuthorizationServerConfig.userService)
↑ ↓
| userService (field private com.oauthserver.repository.user.UserRepository com.oauthserver.service.impl.UserServiceImpl.userRepository)
↑ ↓
| userRepository
↑ ↓
| (inner bean)#503c3100
↑ ↓
| entityManagerFactory
└─────┘
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS