Spring OAuth - no qualification bean of type PlatformTransactionManager

I was able to successfully integrate OAuth2 into my previous application (REST service) by replacing BASIC auth.

Then I got the following exception:

No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: transactionManagerDB2,transactionManager

When I remove the bean transactionManagerDB2, it started working fine. I have 2 transaction managers because I have two related databases.

Since I have InMemoryTokenStore, I am curious to demand TransactionManager. (And why Oauth cannot select "transactionManager" by default)

Somehow I set up CustomeUserDetailService through configureGlobal(AuthenticationManagerBuilder auth){}, which worked fine before and now with a single TransactionManager.

I used sparklr-boot Spring Boot application to integrate OAuth with my application. (Thanks to Dave Syer for making such a simple, easy-to-understand example)

I use:

  • Spring 4.2.5
  • Spring Security 4.0.4
  • Spring OAuth 2.0.9
  • (No Spring Download)
+4
source share
1 answer

The problem is that methods in DefaultTokenServices are annotated using @Transactional. Therefore, even if you are not using a database, you need to add a bean transaction manager like this to the authorization server configuration:

@Bean
    public PlatformTransactionManager annotationDrivenTransactionManager() {
        return new ResourceTransactionManager() {
            @Override
            public Object getResourceFactory() {
                return null;
            }

            @Override
            public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
                return null;
            }

            @Override
            public void commit(TransactionStatus status) throws TransactionException {

            }

            @Override
            public void rollback(TransactionStatus status) throws TransactionException {

            }
        };
    }
0
source

All Articles