tags:

views:

47

answers:

1

Can I make the spring service classes final? Is there any harm doing that? Nobody is going to extend the class. Is there any issue?

public final class MyService {
   // Depedencies go here.
}
+4  A: 

Don't make them final. If you use any AOP (including transaction support) on concrete classes, spring will use CGLIB to dynamically extend your class in order to make a proxy. And the requirement for CGLIB to work is to have your classes non-final. Otherwise an exception will be thrown.

Bozho
Good answer. So DAO classes can be `final`? They are not usually transactional.
fastcodejava
Well, then _can_, but be careful with that as well. You might at some point add some AOP to them as well.
Bozho