Tôi đã làm việc với ứng dụng web với applicationContext.xml trong WEB-INF/config/applicationContext.xml. Bây giờ tôi cần phải thực hiện một số công cụ kiểm thử là ứng dụng độc lập, có thể sử dụng cùng một applicationContext.xml, nhưng có vấn đề với đường dẫn đến cấu hình cho lớp ClassPathXmlApplicationContext.Đường dẫn phải tới applicationContext.xml bằng ClassPathXmlApplicationContext
Tôi biết rằng khi tôi sao chép applicationContext.xml vào gói mặc định (nơi .java cư trú) tôi có thể sử dụng ClassPathXmlApplicationContext ("applicationContext.xml"), nhưng điều này có cần thiết không?
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AdminTool {
private Logger log = Logger.getLogger(getClass());
/** all below doesn't work - FileNotFoundException) **/
private static final ApplicationContext ac = new ClassPathXmlApplicationContext("/WEB-INF/config/applicationContext.xml");
private static final ApplicationContext ac = new ClassPathXmlApplicationContext("config/applicationContext.xml");
private static final ApplicationContext ac = new ClassPathXmlApplicationContext("../config/applicationContext.xml");
public static void main(String[] args) {
new AdminTool();
}
public AdminTool() {
log.debug(ac);
}
}
Tôi đã suy nghĩ về việc chạy AdminTool của mình bằng cách sử dụng webapp.war. Nó sẽ có thể sử dụng FileSystemXmlApplicationContext? – marioosh
@marioosh Không, trong một cuộc chiến bạn có những vấn đề tương tự như trong một cái lọ: không có tệp nào, chỉ là các mục nhập. Chiến tranh có được triển khai trong một thùng chứa servlet hay cục bộ không? –
@Patrick Tôi muốn sử dụng lớp AdminTool từ .war mà không cần triển khai. PS: Tôi có dự án maven: FileSystemXmlApplicationContext mới ("src/main/webapp/WEB-INF/config/applicationContext.xml"); hoạt động khi tôi chạy AdminTool trong Eclipse – marioosh