[Tapestry5] tapestry5.2.5测试时找不到服务实现类

hxzon 2011-04-12
tapestry5.2.5测试时找不到服务实现类

public class TestContract extends Assert {
public static void main(String args[]) {
String appPackage = "com.ptswitch.material";
String appName = "app";
PageTester tester = new PageTester(appPackage, appName, "WebRoot");
Document doc = tester.renderPage("CreateContract");
System.out.println(doc);
}
}
抛出异常No service implements the interface com.ptswitch.material.service.HLogService.

此异常应该是因为这个服务使用spring applicationContext.xml管理的,现在用tapestry test测试,抛出此异常应该怎么办?
hxzon 2011-04-13
使用spring bean已解决,如下
——————————–
public class MaterialTester extends PageTester {
private MockServletContext servletContext;

public MaterialTester() {
super(“com.ptswitch.material”, “app”, “WebRoot”);
Registry registry = this.getRegistry();
// Set Tapestry registry in mock servlet context
servletContext.setAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME, registry);
}

@Override
protected ModuleDef[] provideExtraModuleDefs() {
// Set spring configuration files location
servletContext = new MockServletContext();
servletContext.addInitParameter(“contextConfigLocation”, “WebRoot/WEB-INF/applicationContext.xml”);
servletContext.addInitParameter(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, “true”);
servletContext.setAttribute(“org.springframework.web.context.WebApplicationContext.ROOT”, new org.springframework.context.support.FileSystemXmlApplicationContext(
“WebRoot/WEB-INF/applicationContext.xml”));
return new ModuleDef[] { new SpringModuleDef(servletContext) };
}
}
————————————
public static void main(String args[]) {
PageTester tester = new MaterialTester();
Document doc = tester.renderPage(“user/login”);
System.out.println(doc);
}
但又有一个问题:
Unable to delegate method invocation to property ‘HTTPServletRequest’ of , because the property is null.
请问谁能指点一下?
hxzon 2011-04-14
http://spreadthesource.com/2010/08/start-spring-application-context-for-your-tapestry-unit-tests/#comments


http://tieba.baidu.com/f?kz=1050157519
Global site tag (gtag.js) - Google Analytics