spring配置文件无法读取properties参数报dataSource注入错误

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_42571004/article/details/102717120

Failed to convert property value of type ‘java.lang.String’ to required type ‘int’ for property ‘maxActive’;
部署好maven项目在tomcat启动报错,各种调试。
我是将所有的项目配置properties文件同一在一个文件中(spring-profile-config.xml),

	
	<!-- 开发环境 -->
	<beans profile="dev">
		<!-- 开发环境下加载的propertie文件 -->
		<bean id="propertyConfigurer" class="com.naturent.pattern.util.PropertyConfigurer">
			<property name="locations">
				<list>
					<value>classpath:profiles/dev/db-config.properties</value>
					<value>classpath:profiles/dev/file-url.properties</value>
					<value>classpath:profiles/dev/redis.properties</value>
					<value>classpath:profiles/dev/weixin.properties</value>
					<!-- <value>classpath:profiles/dev/ueditor.properties</value> -->
					<!-- <value>classpath:dev/mail-config.properties</value> -->
				</list>
			</property>
		</bean>
	</beans>
	
	<!-- 生产环境 -->
	<beans profile="prod">
		<!-- 生产环境下加载的propertie文件 -->
		<bean id="propertyConfigurer" class="com.naturent.pattern.util.PropertyConfigurer">
			<property name="locations">
				<list>
					<value>classpath:profiles/prod/db-config.properties</value>
					<value>classpath:profiles/prod/file-url.properties</value>
					<value>classpath:profiles/prod/redis.properties</value>
					<value>classpath:profiles/prod/weixin.properties</value>
					<!-- <value>classpath:profiles/prod/ueditor.properties</value> -->
					<!-- <value>classpath:profiles/prod/*.properties</value> -->
					<!-- <value>classpath:prod/mail-config.properties</value> -->
				</list>
			</property>
		</bean>
	</beans>

目录结果
在这里插入图片描述
在web.xml配置

 <!-- 读取的配置信息 -->
  <context-param>
      <param-name>spring.profiles.default</param-name>
      <param-value>dev</param-value>
  </context-param>

这样配置是正确的,但依旧报错,
后在需要使用properties文件的sprong配置中加入这样一段

<!-- 引入配置文件 -->
<bean id="propertyConfigurer"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <list>
   <value>classpath:profiles/dev/db-config.properties</value>
   </list>
  </property>
 </bean>

启动tomcat错误消失,然后删除这段bean配置,再次运行,能够正确读取到统一配置的properties信息。很奇怪。

猜你喜欢

转载自blog.csdn.net/weixin_42571004/article/details/102717120