Spring EL中的类操作符

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="saxophone" class="com.stono.sprtest.Saxophone"></bean>
    <bean id="cymbal" class="com.stono.sprtest.Cymbal"></bean>
    <bean id="duke" class="com.stono.sprtest.Duke">
        <property name="instruments">
            <set>
                <ref bean="saxophone"/>
                <ref bean="saxophone"/>
                <ref bean="cymbal"/>
                <null/>
            </set>
        </property>
        <property name="pi" value="#{T(java.lang.Math).PI}"/>
        <property name="name" value="#{saxophone.getName()}" />
        <property name="name2" value="#{saxophone.name}" />
        <property name="name3" value="#{saxophone.getName()?.toUpperCase()}" />
        <property name="name4" value="#{saxophone.name?.toUpperCase()}" />
    </bean>
</beans>
时间: 2024-08-05 15:24:33

Spring EL中的类操作符的相关文章

SpringBoot中在普通类里面加载Spring容器中的类

前言 在我们的工作中,经常会遇到需要在普通类中使用放在Spring容器中的类的情况.最常见的情况大概就是有一个类他的属性的是通过spring的配置文件读取的.这样这个类必然要交给Spring容器进行管理.这个时候如果我们在普通类中直接new这个类是不可以拿到的.属性值不会加载成功.下面介绍一个方法. 实现 封装一个beanutil 我们获取spring容器中的类,都从这个工具类里面来获取. import org.springframework.context.ConfigurableApplic

Spring MVC中一般类使用service

在Spring MVC中,Controller中使用service只需使用注解@Resource就行,但是一般类(即不使用@Controller注解的类)要用到service时,可用如下方法: 1.SpringContextUtil package com.test.framework.utils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBea

解决spring boot中普通类中使用service为null 的方法

我使用的是springboot+mybatisplus +mysql1.创建一个SpringUtil工具类 import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public final class SpringUtil im

spring 使用Spring表达式(Spring EL)

Spring还提供了更灵活的注入方式,那就是Spring表达式,实际上Spring EL远比以上注入方式强大,我们需要学习它.Spring EL拥有很多功能. 使用Bean的id来引用Bean. •调用指定对象的方法和访问对象的属性. •进行运算. •提供正则表达式进行匹配. •集合配置. 这些都是Spring表达式的内容,使用Spring表达式可以获得比使用Properties文件更为强大的装配功能,只是有时候为了方便测试可以使用Spring EL定义的解析类进行测试,为此我们先来认识它们.

Spring Aop中,获取被代理类的工具

在实际应用中,顺着过去就是一个类被代理.反过来,可能需要逆向进行,拿到被代理的类,实际工作中碰到了,就拿出来分享下. 1 /** 2 * 获取被代理类的Object 3 * @author Monkey 4 */ 5 public Object getTarget(Object proxy) throws Exception { 6 7 if(!AopUtils.isAopProxy(proxy)) { 8 //不是代理对象 9 return proxy; 10 } 11 12 if(AopUt

Spring boot中普通工具类不能使用@Value注入yml文件中的自定义参数的问题

在写一个工具类的时候,因为要用到yml中的自定义参数,使用@Value发现值不能正常注入,都显示为null: yml文件中的自定义格式 调用工具类的时候不能new的方式 要使用@Autowired的方式注入进来, new会导致部分环境未加载,尽可能舍弃new的方式,交付spring管理 而工具类也是需要交给spring管理.需要在工具类上加上 @Component注解然后注意一下的是 在springframework下不能@Autowired静态变量 所以在变量上不能有 static 怎么扫描注

在spring项目中,普通类注入获取Bean,实现ApplicationContextAware接口

在平时spring项目中,某个不能注入Bean的项目中要获取Bean. @Component public class SpringUtil implements ApplicationContextAware { private static ApplicationContext applicationContext = null; public SpringUtil() { } public void setApplicationContext(ApplicationContext arg0

Spring基础系列6 -- Spring表达式语言(Spring EL)

Spring基础系列6 -- Spring表达式语言(Spring EL) 转载:http://www.cnblogs.com/leiOOlei/p/3543222.html 本篇讲述了Spring Expression Language —— 即Spring3中功能丰富强大的表达式语言,简称SpEL.SpEL是类似于OGNL和JSF EL的表达式语言,能够在运行时构建复杂表达式,存取对象属性.对象方法调用等.所有的SpEL都支持XML和Annotation两种方式,格式:#{ SpEL exp

Spring EL hello world实例

Spring EL与OGNL和JSF EL相似,计算评估或在bean创建时执行.此外,所有的Spring表达式都可以通过XML或注解. 在本教程中,我们将学习如何使用Spring表达式语言(SpEL),注入字符串,整数,Bean到属性,无论是在XML和注释. 1. Spring Beans 两个简单Bean,后来利用 SpEL 注入值到属性,在 XML 和 注释. package com.yiibai.core; public class Customer { private Item item