Spring实战2.3.3 在SpEL中筛选集合

目录

spring 配置问题:

 The prefix "util" for element "util:list" is not bound"

 The prefix "aop" for element "aop:config" is not bound.


spring 配置问题:

Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound.

 The prefix "util" for element "util:list" is not bound"

解决方法:

在spring的头部文件中没有引入:

xmlns:util="http://www.springframework.org/schema/util"

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd

要用到Spring的util(包括util:list等),xml文件中的beans中需要添加一些有关util的信息:

<?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:util="http://www.springframework.org/schema/util" xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <!-- bean definitions here -->

</beans>

首先定义一个City类,City.java

package com.habuma.spel.cities;

public class City {
	
	private String name;
	private String state;
	private int population;
	
	public City(){};
	
	public String getName(){
		return name;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getState(){
		return state;
	}
	
	public void setState(String state){
		this.state = state;
	}
	
	public int getPopulation(){
		return population;
	}
	
	public void setPopulation(int population){
		this.population = population;
	}
}

使用<util:list>元素在Spring里spring-idol.xml配置一个包含City对象的List集合

<!-- 2.3.3 在SpEL中筛选集合 -->
	<util:list id="cities"> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Chicago" p:state="IL" p:population="2853114"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Atlanta" p:state="GA" p:population="537958"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Dallas" p:state="TX" p:population="1279910"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Houston" p:state="TX" p:population="2242193"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Odessa" p:state="TX" p:population="90943"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="El Paso" p:state="TX" p:population="613190"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Jal" p:state="NM" p:population="1996"/> 
		<bean class="com.habuma.spel.cities.City" 
			p:name="Las Cruces" p:state="NM" p:population="91865"/> 
	</util:list> 

<util:list>元素是由Spring的util命名空间所定义的。它创建了一个java.util.List类型的Bean,这个集合里包含了所有以上配置的Bean。

 The prefix "aop" for element "aop:config" is not bound.

<?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:util="http://www.springframework.org/schema/util"
    xmlns:p="http://www.springframework.org/schema/p"   
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"   
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
</bean>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值