Я хочу проверить Struts действия, но я столкнулся со следующей проблемой:Junit испытание Struts2 действия с весной
SEVERE: [09:16.218] Error building bean
кажется, что весна не делать инъекции зависимостей. Действительно, если я создаю конструктор по умолчанию, я получаю NPE, потому что служба не создается. Мой модульный тест расширяет StrutsSpringTestCase, так почему мое действие не является инстанцированным правильно?
Вот мои действия:
public ControllerAuthentification(LdapUserService service) {
this.ldapUserService = service;
}
public String connection() {
if (userLdap != null) {
ldapUserService.save(userLdap);
addActionMessage(getText("success.connect"));
return SUCCESS;
}
return INPUT;
}
испытания Единица измерения:
public class ControllerAuthentificationTest extends StrutsSpringTestCase {
public void testConnection() throws Exception {
request.setParameter("userLdap.login", "login");
request.setParameter("userLdap.password", "password");
proxy = getActionProxy("/connection");
ControllerAuthentification action = (ControllerAuthentification) proxy.getAction();
String result = proxy.execute();
assertTrue("it would be true", result.equals(Action.SUCCESS));
}
}
ApplicationContext
<bean id="ldapUserService" class="sword.plateformetest.service.impl.LdapUserServiceImpl" />
<bean id="ldapUserAuthAction" scope="prototype"
class="sword.plateformetest.action.ControllerAuthentification">
<constructor-arg ref="ldapUserService" />
</bean>
и мой web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Стек след:
SEVERE: [56:08.596] Error building bean
2013-08-26 13:56:08,600 ERROR sword.plateformetest.action.ControllerAuthentificationTest.testConnection:37 - error
Unable to intantiate Action!
at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
at com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:397)
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.StrutsTestCase.getActionProxy(StrutsTestCase.java:137)
at sword.plateformetest.action.ControllerAuthentificationTest.testConnection(ControllerAuthentificationTest.java:34)
Какие журналы отображаются? Запускает ли пружинный контейнер? –
Я добавляю журналы. Как я могу узнать, начался ли весенний контейнер? – Guillaume
Должен быть напечатан в журналах. –