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服务没有自动装配。请帮忙
答案 0 :(得分: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