How to use existing java class from grails

后端 未结 5 616
执念已碎
执念已碎 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:57

    Put your source in src/java. Then in conf/spring/resources.groovy, you can do, for example:

    // Place your Spring DSL code here
    beans = {
        myJavaFunction(com.my.javafunction)
    
    }
    

    Then you can inject it into your controllers or services with:

    def myJavaFunction
    

提交回复
热议问题