`

Spring中加载ApplicationContext.xml文件的方式

阅读更多
主要是载入Spring配置文件的方式不同。
ClassPathResource --- 从系统的类路径中加载
FileSystemResource --- 从文件系统加载,比如说自己指定配置文件的全路径
InputStreamResource --- 从输入流中加载
ServletContextResource --- 从Servlet 上下文环境中加载
UrlResource --- 从指定的Url加载

Spring中加载ApplicationContext.xml文件的方式:
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContent.xml");
UserDao userDao=(UserDao)context.getBean("userDao");

多文件:
ClassPathXmlApplicationContext xml=new ClassPathXmlApplicationContext(new String[]{"applicationContent.xml"});
BeanFactory bean=xml;
UserDao userDao=(UserDao)bean.getBean("userDao");
分享到:
评论

相关推荐

    Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件1

    Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件1

    MyContextLoaderPlugIn.jar

    和Spring中OpenSessionInView由于org.springframework.web.struts.ContextLoaderPlugIn中保存同一个对象的名不同导致openSessionInView失效 稍微修改后在struts-config.xml中使用MyContextLoaderPlugIn.jar包中...

    Spring入门.docx

    加载xml文件使用ClassPathXmlApplicationContext("applicationContext.xml") (3)BeanFactory(bean工厂)与ApplicationContext(容器)对比: 所有在xml里配置的Bean标签最后都会转换为BeanDefinition对象存放在...

    spring-test-4.1.2.RELEASE-sources.jar

    因为所有的Bean都需要在applicationContext.xml中加载好,之后再通过@Resource去取得。如果每次都要整个业务流做的差不多了再去测试,这样效率很低,也很麻烦。如果单独去写一个测试用类,这样太繁琐了。于是想起...

    5.ssh整合1.rar

    .添加spring开发能力.加载hibernate框架.生成java数据对象和映射.编写接口,与实现类.修改spring配置文件applicationContext.xml。 编写测试类

    spring技术入门相关源码

    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); //输出spring容器 System.out.println(ctx); //打印加载的bean名称 System.out.println(java.util.Arrays....

    spring-mvc代码示例+注释+文件解析(可直接运行)

    2、spring-mvc配置文件包括两部分,一个是spring传统配置文件,在代码中为“applicationContext.xml”,主要配置代码中各种bean以及依赖关系;另外一个是spring-mvc特有的配置文件,处理跳转的代理类得(相当于...

    BOS技术整理-05

    将cxf配置在web.xml中 与applicationContext.xml中声明服务的bean 创建一个maven项目(war) 编写实体类,Service 导入applicationContext.xml 配置cxf的发布 客户端测试代码 WebService-RS ...

    springweb3.0MVC注解(附实例)

    web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: <?xml...

    spring结合mongodb例子(maven java project)

    1.例子中还说明了配置文件放在maven的src/main/java下与放在第二个src下的main目录下的不同结果及加载方式:AppTest.java文件 2.列出配置文件的加载方式 a.通过spring-test的注解方式加载配置文件:AppTest2.java b....

    spring配置文件详解--真的蛮详细

    Spring配置文件是一个或多个标准的XML文档,applicationContext.xml是Spring的默认配置文件,当容器启动时找不到指定的配置文档时,将会尝试加载这个默认的配置文件。 下面列举的是一份比较完整的配置文件模板,...

    Spring AOP配置源码

    在类上标注@ContextConfiguration(locations="classpath:applicationContext.xml")意思是去classpath路径下加载applicationContext.xml @Resource(name="userService")意思是把userService注入进来 最终输出结果为:...

    spring学习笔记

    ..............................................................................................................9 1.3.7Spring 框架加载配置文件:..............................................................

    使用Struts+Spring+Hibernate整合开发例子

    注意:在添加hibernate框架时,选择生成spring configuration file (applicationContext.xml)。 这里是使用spring配置文件管理hibernate。 先配置mysql数据驱动,打开eclipse database explorer perspective,选择...

    WebChat:使用SSM框架搭建一个WEBCHAT在线聊天的软件

    Web.xml文件中只做一件事情,加载applicationContext.xml,spring容器会创建数据源对象,sqlSessionFactory工厂对象,最重要的创建了所有的Mapper代理对象 访问LOING.JSP页面,并填写登录ID和密码,点击登录按钮...

    spring+springMVC+hibernate集成

    spring+springMVC+hibernate集成,包括配置文件applicationContext.xml、web.xml、springMVC-servlet.xml

    Java打包可执行后的执行脚本cmd,sh,spring

    import org.mybatis.generator.config.xml.ConfigurationParser; import org.mybatis.generator.exception.InvalidConfigurationException; import org.mybatis.generator.exception.XMLParserException; import org...

    Quartz动态修改时间,java实现修改CronExpression方法

    下载导入就可以用,执行test类的main方法加载spring applicationContext.xml配置文件,启动Quartz定时器.修改spring配置文件的配置时间.详细看注释

    Spring中文帮助文档

    6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入...

Global site tag (gtag.js) - Google Analytics