开发者

Passing a service to non-service in grails?

I have a non-service class which is defined as such:

class A{
   B b
   A( B b ){ this.b = b }
}

where B is a grails service. In my unit tests, I tried this:

A a = new A( new B() );

For some reason, however, b never gets set, and the variable b [local, the argument to the mehod] i开发者_如何转开发sn't even visible in Intelli-J's debugger when running the test. That is, I can rename the argument to service, and the debugger shows it as undefined.

When I try to start a server, I get Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException, so I'm assuming this is related.

What's going on here?


That seems like a strange scenario. What is A doing? Is there any chance that A is really a service?

I'd suggest making A a service, in which case you can inject the B service into it as per normal usage.

I don't think that doing 'new B()' would really be valid, unless B has no dependencies on anything (autowired fields). Perhaps injecting B into the test would be better?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜