Spring 3提供了一个新的
jdbc名称空间,其中包括对嵌入式数据库(包括HSQLDB)的支持。这样就可以解决这一部分。
我想知道什么是“内部解决方案”。您可以使用批注(JPA或Hibernate批注)对您的域对象进行ORM,那么为什么需要“内部解决方案”?例如:
<bean id="sessionFactory" p:dataSource-ref="dataSource" p:packagesToScan="myapp.model" />
就实施测试而言,请使用Spring的TestContext framework。测试看起来可能是这样的(再次假设我在下面的Spring
3中运行,尽管只需将@Inject更改为@Autowired即可在Spring 2.5中运行):
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "/beans-datasource-it.xml", "/beans-dao.xml", "/beans-service.xml", "/beans-web.xml" }) @Transactional public class ContactControllerIT { @Inject private ContactController controller; ... setUp() and tearDown() ... @Test public void testGetContact() { String viewName = controller.getContact(request, 1L, model); ... assertions ... } }例如,您会将嵌入式数据库放入其中
beans-datasource-it.xml。(这里的“
it”代表集成测试,文件位于类路径中。)本示例中的控制器位于中
beans-web.xml,并将自动连接到该
ContactController字段中。
那只是做什么的概述,但希望足以让您入门。



