springboot-16-springboot中引入xml文件
参考原文: http://412887952-qq-com.iteye.com/blog/2293846 使用的是在spring中注入一个bean的方式来测试是否成功, 感觉略不实用, 只碰到过一次dubbo中需要配置文件注入, 其他都可以通过注解注入的方式实现
1, mongdb的配置文件:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.mongo" />
<!-- 获取配置资源 -->
<!-- <context:property-placeholder location="classpath:mongodb-context-config.properties" /> -->
<context:property-placeholder location="classpath:mongodb-context-config.properties" ignore-unresolvable="true"/> <mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}" >
<mongo:options
connections-per-host="${mongo.connectionsPerHost}"
threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}"
connect-timeout="${mongo.connectTimeout}"
max-wait-time="${mongo.maxWaitTime}"
auto-connect-retry="${mongo.autoConnectRetry}"
socket-keep-alive="${mongo.socketKeepAlive}"
socket-timeout="${mongo.socketTimeout}"
slave-ok="${mongo.slaveOk}"
write-number=""
write-timeout="" write-fsync="true"/>
</mongo:mongo>
<!-- 设置使用的数据库 名-->
<mongo:db-factory dbname="test" mongo-ref="mongo"/>
<!-- mongodb的模板 -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
</beans>
资源文件:
mongo.host=www.wenbronk.com
mongo.port=
mongo.connectionsPerHost=
mongo.threadsAllowedToBlockForConnectionMultiplier=
mongo.connectTimeout=
mongo.maxWaitTime=
mongo.autoConnectRetry=true
mongo.socketKeepAlive=true
mongo.socketTimeout=
mongo.slaveOk=true
mongo.writeNumber=
mongo.riteTimeout=
mongo.writeFsync=true
2, 将配置文件引入springboot
XMLSource.java 确保可以被入口程序扫描到
package com.iwhere; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource; /**
* 将外部资源文件引入springboot中
* 在入口类的可扫描环境下
*
* @author wenbronk
* @time 2017年4月6日 下午2:21:30 2017
*/
@Configuration
@ImportResource(locations={"classpath:mongodb/mongodb-context.xml"})
public class XMLSource { }
然后在启动后, 就可以通过MongoTemplate来进行注入了
原文地址: http://412887952-qq-com.iteye.com/blog/2293846
springboot-16-springboot中引入xml文件的更多相关文章
- SPRING IN ACTION 第4版笔记-第二章WIRING BEANS-008-在Java配置文件中引入xml配置文件@Import、@ImportResource
1. package soundsystem; import org.springframework.beans.factory.annotation.Autowired; public class ...
- Spring依赖注入的方式、类型、Bean的作用域、自动注入、在Spring配置文件中引入属性文件
1.Spring依赖注入的方式 通过set方法完成依赖注入 通过构造方法完成依赖注入 2.依赖注入的类型 基本数据类型和字符串 使用value属性 如果是指向另一个对象的引入 使用ref属性 User ...
- .net中创建xml文件的两种方法
.net中创建xml文件的两种方法 方法1:根据xml结构一步一步构建xml文档,保存文件(动态方式) 方法2:直接加载xml结构,保存文件(固定方式) 方法1:动态创建xml文档 根据传递的值,构建 ...
- [Eclipse] eclipse中打开xml文件,使用ctrl+鼠标左键无法跳转至Java源文件【待解决】
eclipse中打开xml文件,使用ctrl+鼠标左键无法跳转至Java源文件: 1. 设置eclipse ctrl + 左键打开源文件代码,如下图,设置都正常 2. 在网上找了很多种办法,均失败,在 ...
- 解决Eclipse中编辑xml文件的智能提示问题,最简单的是第二种方法。
Eclipse for Android xml 文件代码自动提示功能,介绍Eclipse 编辑器中实现xml 文件代码自动智能提示功能,解决eclipse 代码提示失效.eclipse 不能自动提示. ...
- 修改Android中strings.xml文件, 动态改变数据
有些朋友可能会动态的修改Android中strings.xml文件中的值,在这里给大家推荐一种简单的方法.strings.xml中节点是支持占位符的,如下所示: <string name=&qu ...
- 『vue踩坑日常』 在index.html中引入静态文件不生效
Vue日常踩坑日常 -- 在index.html中引入静态文件不生效问题 本文针对的是Vue小白,不喜勿喷,谢谢 出现该问题的标志如下 控制台warning(Resource interpreted ...
- [转]解决Eclipse中编辑xml文件的智能提示问题
转自:http://hi.baidu.com/cghroom/item/48fd2d0dc1fc23c675cd3c3e 摘要: Eclipse for Android xml 文件代码自动提示功能 ...
- 【jsp】怎么在jsp文件中引入静态文件(.js .css)
如果在jsp文件中引入静态文件比如(.js或.css等等),可以在使用 /项目名称/路径 的方式,但是这种方式如果在修改了项目了名称后就显得比较麻烦了.除了之外还许多方式,比如相对路径等等.一般情况下 ...
随机推荐
- HDU1237 简单计算器 2016-07-24 13:34 193人阅读 评论(0) 收藏
简单计算器 Problem Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过 ...
- Linux应用程序中使用math库报undefined reference to `sin'等
出现该问题是因为在Linux中,sin,sqrt等函数是在libm.so库文件中,并非在math.h中. 解决办法:在Ubuntu的gcc编译环境下,直接使用lm参数即可,例如gcc -o Gen G ...
- spring MVC controller中的方法跳转到另外controller中的某个method的方法
1. 需求背景 需求:spring MVC框架controller间跳转,需重定向.有几种情况:不带参数跳转,带参数拼接url形式跳转,带参数不拼接参数跳转,页面也能显示. 本来以为挺简单的一 ...
- Oracle EBS 采购 接收入库 接口开发
http://blog.itpub.net/25164132/viewspace-746657/ 接收入库是项目中会经常碰到的开发,这类开发一般来说比较简单,但是接收入库在Oracle中其实涉及到很多 ...
- [ACM_数据结构] Color the ball [线段树水题][数组开大]
Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次 ...
- npm安装和Vue运行
一.开始: 下载地址:http://nodejs.cn/download/ 下载安装: 直到 二.打开CMD,检查是否正常 在安装目录里新增两个文件夹 然后运行命令:如下图: npm config s ...
- Windows Server 2012 R2部署--安装桌面体验
Windows Server 2012 R2部署(3)---安装桌面体验 1) 打开服务器管理器 2) 选择所有服务器 3)添加角色和功能 4)下一步 5)下一步 6)下一步 ...
- 使用C#创建windows服务续之使用Topshelf优化Windows服务
前言: 之前写了一篇“使用C#创建windows服务”,https://www.cnblogs.com/huangwei1992/p/9693167.html,然后有博友给我推荐了一个开源框架Tops ...
- 编程哲学之C#篇:01——创世纪
我们能否像神一样地创建一个世界? 对于创建世界而言,程序员的创作能力最接近于神--相对于导演,作家,漫画家而言,他们创建的世界(作品)一旦完成,就再也不会变化,创建的角色再也不会成长.而程序员创建的世 ...
- dfs找負環
某些無良出題人可能會卡bfs找負環,所以要用dfs 核心代碼(以jzoj5173為例): #include<bits/stdc++.h> using namespace std; #def ...