【问题标题】:Grails Service not autowired inside jaxrs resource classGrails 服务未在 jaxrs 资源类中自动装配
【发布时间】:2015-09-29 12:19:06
【问题描述】:

Grails 版本 2.2.4 Jax RS 插件版本 0.8

我在 Grails-app 服务文件夹下有 grails 服务,如下所示

@Transactional
class HdfsService {

    def write(){

        Configuration configuration = new Configuration();
        FileSystem hdfs = FileSystem.get( new URI( "hdfs://192.168.4.110:9000" ), configuration );
        Path file = new Path("hdfs://192.168.4.110:9000/vinod/table.html");
        if ( hdfs.exists( file )) { hdfs.delete( file, true ); }
        OutputStream os = hdfs.create( file,
                new Progressable() {
                    public void progress() {
                        //println("...bytes written: [ "+bytesWritten+" ]");
                    } });
        BufferedWriter br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) );
        br.write("Hello World");
        br.close();
        hdfs.close();

    }

}

我的 Grails 应用程序中有一个 JAX-RS 资源,如下所示

class CDSResource implements CDSService {


    def hdfsService;

    @Override
    CDSResponse pushRawData(CDSRequest cdsRequest) {


        println(" Inside CDS Resource")

        // hdfsService.write()

        return null;
    }
}

我发现 Grails 服务没有自动装配。请帮忙

【问题讨论】:

    标签: grails jax-rs


    【解决方案1】:

    你见过Grails 2.x service injection in Groovy/src吗?

    import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
    import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes as GA
        def ctx = SCH.servletContext.getAttribute(GA.APPLICATION_CONTEXT)
        def hdfsService = ctx. hdfsService
    

    【讨论】:

    • 它是否适用于 Grailsapp/resources 文件下的文件?
    猜你喜欢
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多