Swing如何调用Spring的配置文件

刚刚在做一个Swing项目,是借用以前的web项目的框架,用的springMVC+hibernate,
现在想直接调用以前的spring配置文件applicationContext.xml及spring-mvc.xml,应该怎么实现

3个回答

spring注解注入或者ApplicationContext ac = new ClassPathXmlApplicationContext("spring-mvc.xml")的方法

为什么我用test调用这两个配置文件都能成功,用这个方法就不行了呢

package test.bs.service.access;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.bs.service.hospital.IHospitalOrganService;
@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(
locations = {"file:WebRoot/WEB-INF/config/applicationContext.xml",
"file:WebRoot/WEB-INF/config/spring-tservice.xml"})

public class HospitalOrganServiceTest extends AbstractTransactionalJUnit4SpringContextTests {
@Resource
private IHospitalOrganService hospitalOrganService;

@Test
public void HospitalOrganService() throws Exception {    
    System.out.println("Testing HospitalOrgan Service ....");

    try {
         Object[][] positionList =  hospitalOrganService.query();
        if (positionList == null) {
            System.out.println("0");
        } else {
            System.out.println(positionList.length);
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}  

这是Service的test,是可以执行的,但是到swing里就不行了,用你给的方法也不能调用

package springtestpkg;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;

import com.mbmed.nurse.lab1.service.Lab1Service;

public class SpringUtilV3_prjcliTest {

@Test
public void test() throws Exception {
    SpringUtilV3_prjcli.setLocations("C:\\0wkspc\\移动医疗源码\\移动医护\\移动护士站\\honurse\\test\\springtestpkg","applicationContext-service.xml,applicationContext-datasource.xml");
    Lab1Service  c= (Lab1Service) SpringUtilV3_prjcli.getBean( Lab1Service.class);
List li=    c.inspectListByvaa04("11414");
System.out.println(li);



}

@Test
public void test_inspectDetailBylab01() throws Exception {
    SpringUtilV3_prjcli.setLocations("C:\\0wkspc\\移动医疗源码\\移动医护\\移动护士站\\honurse\\test\\springtestpkg","applicationContext-service.xml,applicationContext-datasource.xml");
    Lab1Service  c= (Lab1Service) SpringUtilV3_prjcli.getBean( Lab1Service.class);
List li=    c.inspectDetailBylab01(47897);
System.out.println(li);



}

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐