What I have found, is that if you forget to define a transaction manager, or forget to put a @Transactional annotation, then DataSourceUtils.doGetConnection(dataSource) will always get a new connection from the Datasource. So, if you have 5 DAO calls, this will consume 5 slots in the connection pool (this is very bad). We have avoided this by implementing an AOP advice to abort calls to public @Service methods if there is no Transaction manager found.
Code:
@Pointcut("@within(org.springframework.stereotype.Service) && execution(public * *(..))")
public void publicServiceMethods(){}
@Around("publicServiceMethods()")
public Object killUnAnnotatedServiceCalls(ProceedingJoinPoint pjp) throws Throwable {
String methodName = pjp.getSignature().getName();
try {
TransactionAspectSupport.currentTransactionStatus();
} catch (NoTransactionException e){
throw new IllegalStateException("No transactional annotation on a service method! class=" + pjp.getTarget().getClass() + " method=" + methodName);
}
Object o = pjp.proceed();
return o;
}