Skip to content
Snippets Groups Projects
Commit b4912bfd authored by Martin Ledvinka's avatar Martin Ledvinka
Browse files

Updated documentation of the Spring configuration.

parent f44c3b9f
No related branches found
No related tags found
No related merge requests found
......@@ -25,9 +25,10 @@ import org.springframework.context.annotation.Import;
* It is good to separate configuration of different components of the application, because they can then be configured
* independently for example in tests.
*/
// This annotation is required when services without separate interfaces are used. It causes cglib-based proxies of
// the services to be used - see http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/EnableAspectJAutoProxy.html#proxyTargetClass--
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Configuration
@EnableMBeanExport
@Import({WebAppConfig.class, PersistenceConfig.class, ServiceConfig.class})
@Configuration // This class is a Spring configuration
@Import({WebAppConfig.class, PersistenceConfig.class, ServiceConfig.class}) // Import additional configuration classes
public class AppConfig {
}
......@@ -14,6 +14,10 @@ public class TeacherService {
@Autowired
private TeacherDao teacherDao;
// Declarative transaction demarcation. readOnly set to true is good for retrieval operations, because it
// may involve less locking on the lower layers
// If the services are split into interfaces and implementations, the @Transactional annotation usually goes
// to the interface, so that ic can apply to all possible implementations of the service
@Transactional(readOnly = true)
public List<Teacher> findAll() {
return teacherDao.findAll();
......@@ -24,6 +28,7 @@ public class TeacherService {
return teacherDao.findByName(firstName, lastName) != null;
}
// No readOnly here, because we modify the data in this operation
@Transactional
public void persist(Teacher teacher) {
teacherDao.persist(teacher);
......
......@@ -35,6 +35,7 @@ won't be available for autowiring in tests inheriting from this class.
// Reset the Spring context after each tests, recreating all the beans
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
//extend the transactions to whole tests in order to rollback the changes after each test
// Se also http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-tx
@Transactional(transactionManager = "txManager")
public abstract class BaseDaoTestRunner {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment