@Configuration
@ConditionalOnClass (Jaxrsserverfactorybean.class)
@ConditionalOnExpression ("' ${cxf.jaxrs.component-scan} ' = = ' true ' && ' ${cxf.jaxrs.classes-scan} '! = ' True ')
@Import (Springcomponentscanserver.class)
Protected static class Jaxrscomponentconfiguration {
}
/**
* Configuration annotation for a conditional element, depends on the value of a spel
* expression.
*
* @author Dave Syer
*/
@Retention (Retentionpolicy.runtime)
@Target ({elementtype.type, elementtype.method})
@Documented
@Conditional (Onexpressioncondition.class)
Public @interface conditionalonexpression {
/**
* The SPEL expression to evaluate. Expression should return {@code true} if the
* Condition passes or {@code false} if it fails.
* @return the Spel expression
*/
String value () default "true";
}
/*
* Copyright 2012-2016 The original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You are not a use this file except in compliance with the License.
* Obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable or agreed to writing, software
* Distributed under the License is distributed on a "as is" BASIS,
* Without warranties or CONDITIONS of any KIND, either express or implied.
* See the License for the specific language governing permissions and
* Limitations under the License.
*/
Package org.springframework.boot.autoconfigure.condition;
Import Org.springframework.beans.factory.config.BeanExpressionContext;
Import Org.springframework.beans.factory.config.BeanExpressionResolver;
Import Org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Import Org.springframework.context.annotation.ConditionContext;
Import Org.springframework.context.expression.StandardBeanExpressionResolver;
Import org.springframework.core.Ordered;
Import Org.springframework.core.annotation.Order;
Import Org.springframework.core.type.AnnotatedTypeMetadata;
/**
* A Condition that evaluates a spel expression.
*
* @author Dave Syer
* @see Conditionalonexpression
*/
@Order (ordered.lowest_precedence-20)
Class Onexpressioncondition extends Springbootcondition {
@Override
Public Conditionoutcome Getmatchoutcome (Conditioncontext context,
Annotatedtypemetadata metadata) {
string expression = (string) metadata
. Getannotationattributes (ConditionalOnExpression.class.getName ())
. Get ("value");
expression = wrapifnecessary (expression);
String rawexpression = expression;
expression = Context.getenvironment (). resolveplaceholders (expression);
configurablelistablebeanfactory beanfactory = Context.getbeanfactory ();
beanexpressionresolver resolver = (beanfactory! = null)
? Beanfactory.getbeanexpressionresolver (): null;
beanexpressioncontext expressioncontext = (beanfactory! = null)
? New Beanexpressioncontext (Beanfactory, NULL): null;
if (resolver = = null) {
resolver = new Standardbeanexpressionresolver ();
}
Boolean result = (Boolean) resolver.evaluate (expression, expressioncontext);
return new Conditionoutcome (result, conditionmessage
. Forcondition (Conditionalonexpression.class, "(" + rawexpression + ")")
. Resultedin (result));
}
/**
* Allow user to provide bare expression with no ' #{} ' wrapper.
* @param expression Source expression
* @return Wrapped expression
*/
private string Wrapifnecessary (string expression) {
if (!expression.startswith ("#{")) {
Return "#{" + Expression + "}";
}
return expression;
}
}
Learn how annotation expressions are calculated.
Spring Boot conditional annotation expression