<$BlogRSDUrl$>

Friday, April 23, 2004

Webwork dan Spring
Cis! Sonang rupanya nak guna spring ioc dlm webwork. It's either me, or docs utk spring berteraburrr.

Jumpa caranya dlm doc spring reference, bab 10. Antaranya:

1. Menggunakan classpath

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
//.....
ApplicationContext context = new ClassPathXmlApplicationContext("myContext.xml");
ProductService productService = (ProductService) context.getBean("myProductService");



2. Menggunakan path

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
//.....
ApplicationContext context = new FileSystemXmlApplicationContext("C:/myContext.xml");
ProductService productService = (ProductService) context.getBean("myProductService");




Utk no 1 di atas, file myContext.xml perlulah berada dlm root classpath. Utk web apps, file ini boleh diletakkan di dlm web-inf/classes. Utk apps biasa, boleh letak kat mana2 root dir yg didefine dlm classpath. Pilihan saya setakat ini ialah cara 1 spt di atas dan menggunakan file 'default' spring iaitu applicationContext.xml.


Comments: Post a Comment

This page is powered by Blogger. Isn't yours?