How to use existing java class from grails

后端 未结 5 615
执念已碎
执念已碎 2021-02-10 18:19

how can I call a method residing in an existing Java class from Grails app ? Is it necessary/recommended to wrap that up in a service?

5条回答
  •  深忆病人
    2021-02-10 18:50

    is the class in a JAR file in your lib/ folder or in a .java file your src/ folder?

    Either way, there's no need to wrap it in a service. You can construct instances of the class and call methods on it from anywhere.

    If you need to wrap the method calls in a transaction then I'd put it in a service. Otherwise just call it directly. The only other reason to put it in a service is to use the scoping functionality (i.e. if you wanted a new instance of the class created for each request)

    cheers

    Lee

提交回复
热议问题