spring 加載XML文件 – JAVA編程語言程序開發技術文章

java讀取文件幫助類:

[java] 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
 
/**
 * 取得spring 的配置文件
 * @author Administrator
 *
 */ 
public class ApplicationConxtXML { 
     
    public static ApplicationContext getApplicationConxtXMLPropertise(){ 
         
        String[] springConfigArray = { "applicationContext.xml" }; 
        ApplicationContext ctx = new ClassPathXmlApplicationContext(springConfigArray); 
        return ctx; 
         
         
    } 
 

調用:
[java] 
import org.springframework.context.ApplicationContext; 
 
import com.ecd.boss.domain.CopyCategoryImagesService; 
import com.ecd.boss.utils.ApplicationConxtXML; 
 
public class CopyCategoryImagesTsk { 
     www.aiwalls.com
    public static void main(String… args) { 
        ApplicationContext cxt = ApplicationConxtXML 
                .getApplicationConxtXMLPropertise(); 
        CopyCategoryImagesService copyCategoryImagesService = (CopyCategoryImagesService) cxt 
                .getBean("copyCategoryImagesService"); 
         
        int areal[] = {1,4}; 
        copyCategoryImagesService.copyImages(areal); 
         
    } 
     
 

發佈留言