4

I was successfully able to integrate OAuth2 to my previous application (a 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 to working fine. I have 2 transaction managers because I have 2 connected databases.

Since I have a InMemoryTokenStore, I'm curious about the require of a TransactionManager. (And why Oauth is not able pick up "transactionManager" by default name)

Somehow I have configured a CustomeUserDetailService via configureGlobal(AuthenticationManagerBuilder auth){}, which was working 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 to make such simple easy to understand example)

I'm using:

  • Spring 4.2.5
  • Spring Security 4.0.4
  • Spring OAuth 2.0.9
  • (No Spring Boot)
Community
  • 1
  • 1
sura2k
  • 7,365
  • 13
  • 61
  • 80

1 Answers1

0

The problem is that methods in DefaultTokenServices are annotated with @Transactional. So even if you're not using a database, you'll need to add a transaction manager bean like this in your 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 {

            }
        };
    }
Neets
  • 4,094
  • 10
  • 34
  • 46