That old Spring magic has me in its SpEL

Post on 16-Jan-2015

2.399 views 0 download

Tags:

description

Presentation on the Spring Expression Language that I gave at SpringOne/2GX 2009 in New Orleans, LA.

Transcript of That old Spring magic has me in its SpEL

That old Spring magic has me in its SpEL

Craig Walls

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

About me

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

About me

• Java, Spring, and OSGi fanatic

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

About me

• Java, Spring, and OSGi fanatic

• Principal consultant with Improving Enterprises

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

About me

• Java, Spring, and OSGi fanatic

• Principal consultant with Improving Enterprises

• Author

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

About me

• Java, Spring, and OSGi fanatic

• Principal consultant with Improving Enterprises

• Author

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Agenda

3

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Agenda

• Introducing SpEL

3

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Agenda

• Introducing SpEL

• Using SpEL

3

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Agenda

• Introducing SpEL

• Using SpEL

• SpEL Essentials

3

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Agenda

• Introducing SpEL

• Using SpEL

• SpEL Essentials

• A few SpEL incantations

3

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Agenda

• Introducing SpEL

• Using SpEL

• SpEL Essentials

• A few SpEL incantations

• Q & A

3

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Download the examples

Approximately the same code...

http://spring.habuma.com/examples/SpEL-examples.zip

4

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Introducing SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

• The Spring Expression Language

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

• The Spring Expression Language

• Much like Unified EL, OGNL, JBoss EL, and others

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

• The Spring Expression Language

• Much like Unified EL, OGNL, JBoss EL, and others

• Will be used across entire Spring portfolio

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

• The Spring Expression Language

• Much like Unified EL, OGNL, JBoss EL, and others

• Will be used across entire Spring portfolio

• Succinctly express complex concepts

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

• The Spring Expression Language

• Much like Unified EL, OGNL, JBoss EL, and others

• Will be used across entire Spring portfolio

• Succinctly express complex concepts

• Can be used to wire bean properties

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

What is SpEL

• New in Spring 3.0– Originally conceived in Spring.NET

• The Spring Expression Language

• Much like Unified EL, OGNL, JBoss EL, and others

• Will be used across entire Spring portfolio

• Succinctly express complex concepts

• Can be used to wire bean properties

• Can be used outside of Spring

6

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Using SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Configuring beans with SpEL (XML)

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Configuring beans with SpEL (XML)

<bean id="appConfigurer" class="com.habuma.spel.tests.Witch"> <property name="name" value="#{systemProperties['WITCH_NAME']}" /></bean>

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Configuring beans with SpEL (@Value)

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Configuring beans with SpEL (@Value)

@Componentpublic class Wizard { @Value("#{systemEnvironment['WIZARD_NAME']}") private String name;

// ...}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Programming with SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Programming with SpEL

ExpressionParser parser = new SpelAntlrExpressionParser();

StandardEvaluationContext context = new StandardEvaluationContext(rootObject);

Expression ex = parser.parseExpression("witches.^[isWicked()]");

Witch wickedWitch = (Witch) ex.getValue(context);

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Essential SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

#{42}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

#{42} #{3.1415926}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

#{42} #{3.1415926}

#{1e4}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

#{true}

#{42} #{3.1415926}

#{1e4}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

#{true} #{false}

#{42} #{3.1415926}

#{1e4}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Literal expressions

#{'abracadabra'}

#{true} #{false}

#{42} #{3.1415926}

#{null}

#{1e4}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{systemProperties['WIZARD_NAME']}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{systemProperties['WIZARD_NAME']}

#{systemProperties.WIZARD_NAME}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{systemProperties['WIZARD_NAME']}

#{systemProperties.WIZARD_NAME}

#{systemEnvironment['WIZARD_NAME']}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{systemProperties['WIZARD_NAME']}

#{systemProperties.WIZARD_NAME}

#{systemEnvironment['WIZARD_NAME']}

#{systemEnvironment.WIZARD_NAME}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{systemProperties['WIZARD_NAME']}

#{systemProperties.WIZARD_NAME}

#{systemEnvironment['WIZARD_NAME']}

#{systemEnvironment.WIZARD_NAME}

#{wizardBean.name}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{systemProperties['WIZARD_NAME']}

#{systemProperties.WIZARD_NAME}

#{systemEnvironment['WIZARD_NAME']}

#{systemEnvironment.WIZARD_NAME}

#{wizardBean.name}

Only available when using SpEL in Spring configuration

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{request.getParameter('wizardId')}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{request.getParameter('wizardId')}

#{session.getAttribute('wizard')}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ready-to-use variables

#{request.getParameter('wizardId')}

#{session.getAttribute('wizard')}

Can only be used to configure appropriately-scoped beans

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Constructors

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Constructors

#{new com.habuma.spel.tests.Wizard('Gandalf')}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Constructors

#{new com.habuma.spel.tests.Wizard('Gandalf')}

#{new String('hokus pokus')}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing object members

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing object members

#{elf.name}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing object members

#{elf.name}

#{elf.Name}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing object members

#{elf.name}

#{elf.Name}

#{elf.getName()}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing object members

#{elf.name}

#{elf.Name}

#{elf.getName()}

#{elf.name?.length()}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Mixing expressions and text

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Mixing expressions and text

The wizard’s name is #{wizard.name}

Embeds the wizard’s name in some text

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52} #{2.19 + 2.02}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52} #{2.19 + 2.02}

#{77 - 25}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52} #{2.19 + 2.02}

#{77 - 25} #{52 - -25}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52} #{2.19 + 2.02}

#{77 - 25} #{52 - -25}

#{6 * 7}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52} #{2.19 + 2.02}

#{77 - 25} #{52 - -25}

#{6 * 7} #{42 / 6}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Arithmetic operators

#{'Harry' + ' ' + 'Potter'}

#{25 + 52} #{2.19 + 2.02}

#{77 - 25} #{52 - -25}

#{6 * 7} #{42 / 6}

#{44 % 7}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

#{42 > 7}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

#{42 > 7} #{7 > 42}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

#{42 > 7} #{7 > 42}

#{10000 == 1e4}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

#{42 > 7} #{7 > 42}

#{10000 == 1e4}

#{‘Apple’ == ‘Apple’}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

#{42 > 7} #{7 > 42}

#{10000 == 1e4}

#{‘Apple’ == ‘Apple’}

#{‘Apple’ < ‘Orange’}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Relational operators

#{42 > 7} #{7 > 42}

#{10000 == 1e4}

#{‘Apple’ == ‘Apple’}

#{‘Apple’ < ‘Orange’} #{‘Orange’ > ‘Apple’}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Logical operators

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Logical operators

#{witch.isWicked() and witch.name == 'Elphaba'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Logical operators

#{witch.isWicked() and witch.name == 'Elphaba'}

#{witch.isWicked() or witch.name == 'Tattypoo'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Logical operators

#{witch.isWicked() and witch.name == 'Elphaba'}

#{witch.isWicked() or witch.name == 'Tattypoo'}

#{!witch.isWicked()}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ternary and Elvis operator

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ternary and Elvis operator

#{wizard.isGood() ? 'Gandalf' : 'Saruman'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Ternary and Elvis operator

#{wizard.isGood() ? 'Gandalf' : 'Saruman'}

#{wizard.name ?: 'unknown'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The type operator : T()

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The type operator : T()

#{T(String)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The type operator : T()

#{T(String)}

#{T(Math)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The type operator : T()

#{T(String)}

#{T(Math)}

#{T(int)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The type operator : T()

#{T(String)}

#{T(Math)}

#{T(int)}

#{T(java.util.Date)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing class members

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing class members

#{T(Math).floor(42.56)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing class members

#{T(Math).floor(42.56)}

#{T(Math).PI}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

instanceof

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

instanceof

#{‘Sabrina’ instanceof T(String)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

instanceof

#{‘Sabrina’ instanceof T(String)}

#{123 instanceof T(Integer)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

instanceof

#{‘Sabrina’ instanceof T(String)}

#{123 instanceof T(Integer)}

#{123L instanceof T(Long)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

instanceof

#{‘Sabrina’ instanceof T(String)}

#{123 instanceof T(Integer)}

#{123L instanceof T(Long)}

#{1.23 instanceof T(Double)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

instanceof

#{‘Sabrina’ instanceof T(String)}

#{123 instanceof T(Integer)}

#{123L instanceof T(Long)}

#{true instanceof T(Boolean)}

#{1.23 instanceof T(Double)}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Regular expressions

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Regular expressions

#{phoneNumber matches '\\d{3}-\\d{3}-\\d{4}'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Regular expressions

#{phoneNumber matches '\\d{3}-\\d{3}-\\d{4}'}

#{websiteUrl matches 'http://www\\.[a-zA-Z0-9]*\\.(com|edu|net)'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Regular expressions

#{phoneNumber matches '\\d{3}-\\d{3}-\\d{4}'}

#{customerEmail matches '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}'}

#{websiteUrl matches 'http://www\\.[a-zA-Z0-9]*\\.(com|edu|net)'}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Setting variables

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Setting variables

Assuming that the root object has a name property...

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Setting variables

name = 'Broomhilda'

Assuming that the root object has a name property...

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing collection members

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing collection members

#{wizards[0]}

Arrays

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Accessing collection members

#{wizards[0]}

#{magicWords['abracadabra']}

Arrays

Maps and Properties

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Collection selection

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Collection selection

#{witches.?[!isWicked()]}

Select all witches that aren’t wicked

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Collection selection

#{witches.?[!isWicked()]}

#{witches.^[isWicked()]}

Select all witches that aren’t wicked

Select the first wicked witch

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Collection selection

#{witches.?[!isWicked()]}

#{witches.^[isWicked()]}

#{witches.$[isWicked()]}

Select all witches that aren’t wicked

Select the first wicked witch

Select the last wicked witch

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Collection projection

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Collection projection

#{wizards.![name]}

Get the names of all wizards

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The #this variable

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

The #this variable

#{wizards.![name].?[#this > 'G']}

Get the names of all wizards whose name is lexically ordered after ‘G’

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Adding a custom function

31

Only available with programmatic SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Adding a custom function

31

context = new StandardEvaluationContext();parser = new SpelAntlrExpressionParser();context.registerFunction("inEnglish", EnglishNumberInator.class.getDeclaredMethod( "translate", new Class[] {int.class}));

Only available with programmatic SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Adding a custom function

31

context = new StandardEvaluationContext();parser = new SpelAntlrExpressionParser();context.registerFunction("inEnglish", EnglishNumberInator.class.getDeclaredMethod( "translate", new Class[] {int.class}));

Expression ex = parser.parseExpression("#inEnglish(123)");String englishNumber = ex.getValue(context);

Only available with programmatic SpEL

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Demo

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

A few SpEL incantations

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring in a system property (with a default)

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring in a system property (with a default)

<bean class="Wizard"> <property name="name" value= "#{systemProperties['WIZARD_NAME'] ?: 'Gandalf'}" /></bean>

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring bean references

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring bean references

@Value("#{pricingService}")private PricingService pricingService;

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring bean references

@Value("#{pricingService}")private PricingService pricingService;

<property name="pricingService" value="#{pricingService}" />

...or...

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring bean references

@Value("#{pricingService}")private PricingService pricingService;

<property name="pricingService" value="#{pricingService}" />

Don’t do this!

...or...

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Wiring bean references

@Value("#{pricingService}")private PricingService pricingService;

<property name="pricingService" value="#{pricingService}" />

Don’t do this!However...

...or...

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Selective bean wiring

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Selective bean wiring

@Value("#{systemProperties['PRICING'] == 'aggressive'" + "? aggressivePricing : regularPricing}")private PricingService pricingService;

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Selective collection wiring

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Selective collection wiring

public interface TaxRule { boolean appliesToState(String state); double calculateTax(double base);}

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Selective collection wiring

public interface TaxRule { boolean appliesToState(String state); double calculateTax(double base);}

<util:list id="taxRules"> <ref id="revenueTax" /> <ref id="carpetTax" /> <ref id="existenceTax" /> <ref id="justBecauseTax" /></util:list>

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Selective collection wiring

<bean id="taxProcessor" class="TaxProcessor" scope="session"> <aop:scoped-proxy /> <property name="taxRules" value= "#{taxRules.?[appliesToState(session.getAttribute('user').state)]}" /></bean>

public interface TaxRule { boolean appliesToState(String state); double calculateTax(double base);}

<util:list id="taxRules"> <ref id="revenueTax" /> <ref id="carpetTax" /> <ref id="existenceTax" /> <ref id="justBecauseTax" /></util:list>

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

• SpEL expressions are great for doing Spring configuration magic

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

• SpEL expressions are great for doing Spring configuration magic

• SpEL expressions are just Strings...no compile-time help to ensure type-safety, syntax, etc.

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

• SpEL expressions are great for doing Spring configuration magic

• SpEL expressions are just Strings...no compile-time help to ensure type-safety, syntax, etc.

• Don’t abuse SpEL

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

• SpEL expressions are great for doing Spring configuration magic

• SpEL expressions are just Strings...no compile-time help to ensure type-safety, syntax, etc.

• Don’t abuse SpEL

– Remember Goethe’s Sorcerer’s Apprentice

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

• SpEL expressions are great for doing Spring configuration magic

• SpEL expressions are just Strings...no compile-time help to ensure type-safety, syntax, etc.

• Don’t abuse SpEL

– Remember Goethe’s Sorcerer’s Apprentice

– A little bit of magic in the wrong hands can be dangerous

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Parting thoughts

• SpEL expressions are great for doing Spring configuration magic

• SpEL expressions are just Strings...no compile-time help to ensure type-safety, syntax, etc.

• Don’t abuse SpEL

– Remember Goethe’s Sorcerer’s Apprentice

– A little bit of magic in the wrong hands can be dangerous

• Write tests!!!

38

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Q&A

Thank you!Don’t forget to turn in your evaluations!!!