如题:
如果在maven项目中,Spring获取不到配置文件,
把配置文件放到、src/main/resource文件夹下即可
import org.springframework.context.support.ClassPathXmlApplicationContext;
//import com.travelsky.logic.insurance.dto.InsTravelerInfo;
public class InsureTest {
// List<InsTravelerInfo> insTravelerInfos_Main = new ArrayList<InsTravelerInfo>();
public static void main(String args[]) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("danli.xml");
Person p = (Person) ctx.getBean("personzz");
p.setName("zhaozhi");
System.out.println(p.getName());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.*"/>
<bean id="personzz" class="com.maintest.zz.Person">
</bean>
</beans>