简体   繁体   English

纯Java和Grails之间的反射差异

[英]Reflection Difference Between Straight Java and Grails

I'm using a set of APIs developed internally by my company to communicate with some common central services in the organization. 我正在使用公司内部开发的一组API与组织中的一些常见中央服务进行通信。 The APIs can be configured dynamically by runtime configuration to use several transport protocols as needed by the system. 可以通过运行时配置动态配置API,以根据系统需要使用多种传输协议。

The collection of internal APIs are coupled to the IBM WebService thinclient.jar to configure and call all the necessary web services. 内部API的集合耦合到IBM WebService thinclient.jar以配置和调用所有必需的Web服务。 I got the standalone prototype working smoothly, but need to integrate the functionality into several other services that are being developed in Grails. 我使独立的原型顺利运行,但是需要将该功能集成到正在Grails中开发的其他几个服务中。

This is where things fell apart. 这是事情崩溃的地方。 In the code that I've written, we just call a factory method and use that to get a client session and then proceed with our business logic. 在我编写的代码中,我们只是调用工厂方法,并使用该方法来获取客户会话,然后继续进行业务逻辑。 Simple. 简单。 Using the debugger and digging into the API getClient() call, I can see that this gets a generic transport configuration and then binds it to a SOAP transport configuration. 使用调试器并深入研究API getClient()调用,我可以看到它获得了通用的传输配置,然后将其绑定到SOAP传输配置。 From here, the path differs whether it is the pure standalone Java service or the service running in the Grails app. 从这里开始,路径是纯独立Java服务还是在Grails应用程序中运行的服务。

  • In the pure Java standalone, this then is bound to a com.ibm.ws.webservice.engine.client.Service where the initService() method is called and things work as expected. 然后在纯Java独立服务器中,将其绑定到com.ibm.ws.webservice.engine.client.Service ,在其中initService()方法,一切按预期进行。

  • In the Grails app, with the same Java code included, the same place in the code calls to com.springsource.loaded.ri.ReflectiveIntercepter and then after a lot of back and forth in the spring-loaded API, it finally throws a java.lang.reflect.InvocationTargetException. 在Grails应用程序中,包括相同的Java代码,在代码调用com.springsource.loaded.ri.ReflectiveIntercepter的相同位置,然后在弹簧加载的API中反复往复,最终抛出一个Java .lang.reflect.InvocationTargetException。

Does any one have any tips or ideas on how to get the reflection in Grails to behave the same as in the straight Java? 在Grails中如何使反射与纯Java中的反射相同,是否有任何技巧或想法?

I've tried a lot of variations to get to this point and I'm nearing the end of my rope. 为了达到这一点,我已经尝试了多种变体,但我快要走到尽头了。 Ideally, it would be easiest to manage the Grails service that manages our business logic and the Java code that talks to these internal systems together, so I would prefer to get everything (Grails and my Java service code) working together. 理想情况下,最简单的方法是管理用于管理我们的业务逻辑的Grails服务和与这些内部系统对话的Java代码,因此我希望将所有东西(Grails和我的Java服务代码)一起使用。 I briefly tried building a standalone JAR of my service code and all it's dependencies, but had chained dependency conflicts when trying to use that in Grails. 我短暂地尝试过构建一个独立的服务代码及其所有依赖关系的JAR,但是在Grails中尝试使用依赖关系时,存在一系列依赖关系冲突。 My final option will be to stand my Java service up separately from the business logic in the Grails service and just make the calls from the Grails service to the Java service. 我最后的选择是将我的Java服务与Grails服务中的业务逻辑分开,并且仅进行从Grails服务到Java服务的调用。 This is less than ideal. 这不理想。

It's easy when you stumble into the answer... ;-) 当您偶然发现答案时很容易... ;-)

The Grails service runs as expected if I set the run configuration in IDEA to use -noreloading option. 如果我在IDEA中将运行配置设置为使用-noreloading选项,则Grails服务将按预期运行。

grails -noreloading run-app

This stops Grails/IDEA from leaving in the hooks to reload classes on the fly. 这样可以阻止Grails / IDEA离开钩子以即时重新加载类。

Are there any thoughts on whether this is a bug in Grails or the SpringSource Loader classes? 是否对Grails或SpringSource Loader类中的错误有任何想法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM