1.springboot中如何注解方式注入一个map<string,object>?java
查了一天,没有查到经过注解的解决方法,不少只是简单的properties的解决方法,没有看到知足本身需求的,所以注解方式行不通;spring
经过引入外置的xml配置文件,使用@ImportResource注解,在须要list的地方使用@Resource方法引入list;spring-mvc
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <util:list id="controllerHandlers"> <bean class="tk.mybatis.springboot.controller.handler.APPControllerHandler" /> <bean class="tk.mybatis.springboot.controller.handler.SeriesTranHandler" /> </util:list> </beans>
在文件命名上,此处有坑:不能把xml文件名叫做application.xml,若是你已经有了application.yml文件springboot
不然会有文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"的错误提示。mybatis
Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 107; 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。