You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by cmartin81 <ch...@topmartin.com> on 2009/08/07 12:10:01 UTC

Problem testing my action when I’ve got a springbean inside the validators.xml

I want to test my struts actions, but I keep getting this
ClassNotFoundException all the time. 
The problem is that I’ve got a springbean inside the validators.xml. (If I
leave out the springbean in the validators.xml it will run successfully.)

Here some of my validators.xml file:
<validators>
…..
    <validator name="regex"
class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
    <validator name="zipcode"  class="zipCodeValidator"/>
…..
</validators>

Here is the testcode:

        ConfigurationManager configurationManager = new
ConfigurationManager();
        configurationManager.addContainerProvider(new
XWorkConfigurationProvider());
        Configuration config = configurationManager.getConfiguration();
        Container container = config.getContainer();

        ValueStack stack =
container.getInstance(ValueStackFactory.class).createValueStack();
        stack.getContext().put(ActionContext.CONTAINER, container);
        ActionContext.setContext(new ActionContext(stack.getContext()));

        avm = container.getInstance(ActionValidatorManager.class);//
<----------------It fails here


Here is the error:
ava.lang.RuntimeException: java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException
	at
com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:295)
	at
com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:431)
	at
com.opensymphony.xwork2.inject.ContainerBuilder$5.create(ContainerBuilder.java:207)
	at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
	at
com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:507)
	at
com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:517)
	at
com.opensymphony.xwork2.inject.ContainerImpl$9.call(ContainerImpl.java:548)
	at
com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
	at
com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:546)
	at
no.test.web.personal.actions.auto.AutoActionTest.superSetUp(AutoActionTest.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:49)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:36)
	at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException
	at
com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:440)
	at
com.opensymphony.xwork2.inject.ContainerBuilder$5.create(ContainerBuilder.java:207)
	at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
	at
com.opensymphony.xwork2.inject.ContainerImpl$ParameterInjector.inject(ContainerImpl.java:462)
	at
com.opensymphony.xwork2.inject.ContainerImpl.getParameters(ContainerImpl.java:477)
	at
com.opensymphony.xwork2.inject.ContainerImpl.access$000(ContainerImpl.java:34)
	at
com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:293)
	... 22 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
	at
com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:419)
	... 28 more
Caused by: Unable to load validator class zipCodeValidator - validator -
file:///C:/Developer/Prosjekt-src/trunk/klient/private/private-web/validators.xml:24:58
	at
com.opensymphony.xwork2.validator.DefaultValidatorFileParser.parseValidatorDefinitions(DefaultValidatorFileParser.java:120)
	at
com.opensymphony.xwork2.validator.DefaultValidatorFactory.retrieveValidatorConfiguration(DefaultValidatorFactory.java:184)
	at
com.opensymphony.xwork2.validator.DefaultValidatorFactory.parseValidators(DefaultValidatorFactory.java:173)
	at
com.opensymphony.xwork2.validator.DefaultValidatorFactory.<init>(DefaultValidatorFactory.java:44)
	... 33 more
Caused by: java.lang.ClassNotFoundException: zipCodeValidator
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at
com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:146)
	at
com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:96)
	at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:149)
	at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)
	at
com.opensymphony.xwork2.ObjectFactory.buildValidator(ObjectFactory.java:242)
	at
com.opensymphony.xwork2.validator.DefaultValidatorFileParser.parseValidatorDefinitions(DefaultValidatorFileParser.java:117)
	... 36 more


-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p24862185.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
Hello,
Thanks for your answer. 
The test-context.xml is a very simple file. It just contains the
ZipCodeValidator bean, which I need for the validators.xml. I have also
tested that the bean gets instantiated in the class, and it does.  
I think the problem is that there could be 2 containers, and that I can’t
get the ZipCodeValidator bean inside the other container.
(container.getInstance(ActionValidatorManager.class)) .

But does anybody know how I can get the springbean inside the other
container (container.getInstance(ActionValidatorManager.class))?

-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25167033.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by 谢冬鸣 <ms...@gmail.com>.
Hi you said you use
@ContextConfiguration(locations={"classpath:test-context.xml"}).
is there only one configuration file for all classes? if so, maybe a
classpath problem, for some project environment configuration, the classpath
is a little complex (I met this problem in my first maven project), may be
you can try "classpath*:**/*context" or something. in spring, classpath is a
little different with classpath*.

Hope this can help.

BTW, i had met the classpath problem under *Glassfish* server, i have to use
classpath*:xxx,  classpath:xxx  doesn't work.



On Wed, Aug 26, 2009 at 15:59, cmartin81 <ch...@topmartin.com> wrote:

>
> Anyone who can help me?
> --
> View this message in context:
> http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25148306.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
*********************************************
Xie Dongming
MAIL(Gtalk):msys.xdm@gmail.com
Mobie:+86-15071342225

*********************************************

---------------------------------------------------------------------
俺终身奋斗的最低革命纲领:农妇--山泉--有点儿田

Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
Anyone who can help me?
-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25148306.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
Anyone who can help me?
-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p24894957.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
Is there somebody who can help me with this question?

Please :)
-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25799631.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
bump.

-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25531029.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
Anyone?
-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25397337.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
Anyone who can help me?
-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p25270552.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by cmartin81 <ch...@topmartin.com>.
I'm using the following annotation in the test class:
@ContextConfiguration(locations={"classpath:test-context.xml"}) 
@RunWith(SpringJUnit4ClassRunner.class)




newton.dave wrote:
> 
> cmartin81 wrote:
>> I want to test my struts actions, but I keep getting this
>> ClassNotFoundException all the time. 
>> The problem is that I’ve got a springbean inside the validators.xml. (If
>> I
>> leave out the springbean in the validators.xml it will run successfully.)
> 
> How are you initializing the Spring container?
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-testing-my-action-when-I%E2%80%99ve-got-a-springbean-inside-the-validators.xml-tp24862185p24862400.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem testing my action when I’ve got a springbean inside the validators.xml

Posted by Dave Newton <ne...@yahoo.com>.
cmartin81 wrote:
> I want to test my struts actions, but I keep getting this
> ClassNotFoundException all the time. 
> The problem is that I’ve got a springbean inside the validators.xml. (If I
> leave out the springbean in the validators.xml it will run successfully.)

How are you initializing the Spring container?

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org