动态语言支持
Spring 为使用通过动态语言(如 Groovy)定义的类和对象提供了全面的支持。此支持允许您使用受支持的动态语言编写任意数量的类,并让 Spring 容器透明地实例化、配置和依赖注入生成的对象。
Spring 的脚本支持主要针对 Groovy 和 BeanShell。除了这些特定支持的语言之外,还支持 JSR-223 脚本机制,以便与任何支持 JSR-223 的语言提供者集成(从 Spring 4.2 开始),例如 JRuby。
您可以在场景中找到关于此动态语言支持如何立即发挥作用的完整示例。
第一个示例
本章主要详细描述动态语言支持。在深入探讨动态语言支持的方方面面之前,我们先看一个使用动态语言定义的 bean 的快速示例。第一个 bean 使用的动态语言是 Groovy。(本示例的基础取自 Spring 测试套件。如果您想查看其他受支持语言的等效示例,请查阅源代码。)
下一个示例展示了 Messenger
接口,Groovy bean 将实现该接口。请注意,此接口定义在纯 Java 中。注入了对 Messenger
的引用的依赖对象并不知道底层实现是 Groovy 脚本。以下列表显示了 Messenger
接口
package org.springframework.scripting;
public interface Messenger {
String getMessage();
}
以下示例定义了一个依赖于 Messenger
接口的类
package org.springframework.scripting;
public class DefaultBookingService implements BookingService {
private Messenger messenger;
public void setMessenger(Messenger messenger) {
this.messenger = messenger;
}
public void processBooking() {
// use the injected Messenger object...
}
}
以下示例使用 Groovy 实现了 Messenger
接口
package org.springframework.scripting.groovy
// Import the Messenger interface (written in Java) that is to be implemented
import org.springframework.scripting.Messenger
// Define the implementation in Groovy in file 'Messenger.groovy'
class GroovyMessenger implements Messenger {
String message
}
要使用自定义的动态语言标签来定义由动态语言支持的 bean,您需要在 Spring XML 配置文件顶部添加 XML Schema 前导信息。您还需要使用 Spring 有关基于 Schema 配置的更多信息,请参阅基于 XML Schema 的配置。 |
最后,以下示例显示了将 Groovy 定义的 Messenger
实现注入到 DefaultBookingService
类实例中的 bean 定义
<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang https://www.springframework.org/schema/lang/spring-lang.xsd">
<!-- this is the bean definition for the Groovy-backed Messenger implementation -->
<lang:groovy id="messenger" script-source="classpath:Messenger.groovy">
<lang:property name="message" value="I Can Do The Frug" />
</lang:groovy>
<!-- an otherwise normal bean that will be injected by the Groovy-backed Messenger -->
<bean id="bookingService" class="x.y.DefaultBookingService">
<property name="messenger" ref="messenger" />
</bean>
</beans>
bookingService
bean (一个 DefaultBookingService
) 现在可以像往常一样使用其私有成员变量 messenger
,因为注入到其中的 Messenger
实例就是一个 Messenger
实例。这里没有什么特别之处 — 只是普通的 Java 和普通的 Groovy。
希望前面的 XML 片段能够一目了然,但如果不能也请不要过分担心。请继续阅读,以深入了解前面配置的原因和原理。
定义由动态语言支持的 Bean
本节详细描述了如何在任何受支持的动态语言中定义 Spring 管理的 bean。
请注意,本章不试图解释受支持动态语言的语法和惯用语。例如,如果您想使用 Groovy 编写应用程序中的某些类,我们假设您已经了解 Groovy。如果您需要关于动态语言本身的更多详细信息,请查阅本章末尾的更多资源。
通用概念
使用由动态语言支持的 bean 涉及以下步骤
-
为动态语言源代码编写测试(这是理所当然的)。
-
然后编写动态语言源代码本身。
-
在 XML 配置中使用相应的
<lang:language/>
元素定义由动态语言支持的 bean(您可以使用 Spring API 编程式地定义此类 bean,但需要查阅源代码以获取操作指南,因为本章不涵盖此类高级配置)。请注意,这是一个迭代步骤。每个动态语言源文件至少需要一个 bean 定义(尽管多个 bean 定义可以引用同一个源文件)。
前两个步骤(测试和编写动态语言源文件)超出了本章的范围。请查阅您选择的动态语言的语言规范和参考手册,然后继续开发您的动态语言源文件。不过,您最好先阅读本章的其余部分,因为 Spring 的动态语言支持确实对您的动态语言源文件的内容做了一些(小)假设。
<lang:language/>
元素
前一节列表中最后一个步骤涉及定义由动态语言支持的 bean 定义,每个您想要配置的 bean 对应一个定义(这与普通的 JavaBean 配置没有区别)。然而,您可以使用 <lang:language/>
元素来定义由动态语言支持的 bean,而不是指定要由容器实例化和配置的类的完全限定类名。
每种受支持的语言都有一个相应的 <lang:language/>
元素
-
<lang:groovy/>
(Groovy) -
<lang:bsh/>
(BeanShell) -
<lang:std/>
(JSR-223,例如与 JRuby 一起使用)
可用于配置的确切属性和子元素取决于 bean 是使用哪种语言定义的(本章后面特定语言的部分会详细介绍这一点)。
可刷新 Bean
Spring 动态语言支持最引人注目的增值点之一(或许是唯一)就是“可刷新 bean”功能。
可刷新 bean 是由动态语言支持的 bean。通过少量配置,由动态语言支持的 bean 可以监控其底层源文件资源的更改,并在动态语言源文件更改时重新加载自身(例如,当您在文件系统上编辑并保存文件更改时)。
这使您能够将任意数量的动态语言源文件作为应用程序的一部分部署,配置 Spring 容器以创建由动态语言源文件支持的 bean(使用本章中描述的机制),然后(随着需求变化或某些其他外部因素的影响)编辑动态语言源文件,并将所做的任何更改反映在由更改后的动态语言源文件支持的 bean 中。无需关闭正在运行的应用程序(或在 Web 应用程序的情况下无需重新部署)。经过如此修改的由动态语言支持的 bean 会从更改后的动态语言源文件获取新的状态和逻辑。
此功能默认关闭。 |
现在我们可以看一个示例,了解开始使用可刷新 bean 有多容易。要开启可刷新 bean 功能,您只需要在 bean 定义的 <lang:language/>
元素上指定一个额外的属性即可。因此,如果我们沿用本章前面的示例,以下示例展示了我们在 Spring XML 配置中进行哪些更改来实现可刷新 bean
<beans>
<!-- this bean is now 'refreshable' due to the presence of the 'refresh-check-delay' attribute -->
<lang:groovy id="messenger"
refresh-check-delay="5000" <!-- switches refreshing on with 5 seconds between checks -->
script-source="classpath:Messenger.groovy">
<lang:property name="message" value="I Can Do The Frug" />
</lang:groovy>
<bean id="bookingService" class="x.y.DefaultBookingService">
<property name="messenger" ref="messenger" />
</bean>
</beans>
这确实就是您需要做的全部事情。在 messenger
bean 定义上定义的 refresh-check-delay
属性表示在底层动态语言源文件发生任何更改后,bean 会在多少毫秒后刷新。您可以通过将负值分配给 refresh-check-delay
属性来关闭刷新行为。请记住,默认情况下,刷新行为是禁用的。如果您不需要刷新行为,请不要定义该属性。
如果我们运行以下应用程序,就可以体验可刷新功能。(请原谅接下来这段代码中“跳过障碍来暂停执行”的小把戏。)System.in.read()
调用只是为了暂停程序的执行,以便您(在此场景中的开发者)可以去编辑底层动态语言源文件,这样当程序恢复执行时,由动态语言支持的 bean 上的刷新就会被触发。
以下列表显示了此示例应用程序
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scripting.Messenger;
public final class Boot {
public static void main(final String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
Messenger messenger = (Messenger) ctx.getBean("messenger");
System.out.println(messenger.getMessage());
// pause execution while I go off and make changes to the source file...
System.in.read();
System.out.println(messenger.getMessage());
}
}
假设,为了本示例的目的,所有对 Messenger
实现的 getMessage()
方法的调用都必须更改,以便消息被引号包围。以下列表显示了在程序执行暂停时,您(开发者)应该对 Messenger.groovy
源文件进行的更改
package org.springframework.scripting
class GroovyMessenger implements Messenger {
private String message = "Bingo"
public String getMessage() {
// change the implementation to surround the message in quotes
return "'" + this.message + "'"
}
public void setMessage(String message) {
this.message = message
}
}
当程序运行时,在输入暂停之前的输出将是 I Can Do The Frug
。在源文件更改并保存且程序恢复执行后,调用由动态语言支持的 Messenger
实现的 getMessage()
方法的结果是 'I Can Do The Frug'
(注意增加了引号)。
如果更改发生在 refresh-check-delay
值的时间窗口内,则对脚本的更改不会触发刷新。只有在调用由动态语言支持的 bean 上的方法时,脚本的更改才会被实际感知。仅当在由动态语言支持的 bean 上调用方法时,它才会检查其底层脚本源是否已更改。任何与刷新脚本相关的异常(例如遇到编译错误或发现脚本文件已被删除)都会导致致命异常传播到调用代码。
前面描述的可刷新 bean 行为不适用于使用 <lang:inline-script/>
元素符号定义的动态语言源文件(参见内联动态语言源文件)。此外,它仅适用于能够实际检测到底层源文件更改的 bean(例如,通过检查文件系统上动态语言源文件的最后修改日期的代码)。
内联动态语言源文件
动态语言支持还可以处理直接嵌入在 Spring bean 定义中的动态语言源文件。更具体地说,<lang:inline-script/>
元素允许您立即在 Spring 配置文件内部定义动态语言源。一个示例可以阐明内联脚本功能的工作方式
<lang:groovy id="messenger">
<lang:inline-script>
package org.springframework.scripting.groovy
import org.springframework.scripting.Messenger
class GroovyMessenger implements Messenger {
String message
}
</lang:inline-script>
<lang:property name="message" value="I Can Do The Frug" />
</lang:groovy>
如果我们将动态语言源定义在 Spring 配置文件内部是否是良好实践的问题放在一边,<lang:inline-script/>
元素在某些场景下可能会非常有用。例如,我们可能希望快速向 Spring MVC Controller
添加一个 Spring Validator
实现。使用内联源只需要片刻即可完成。(请参阅脚本化验证器获取此类示例。)
理解动态语言支持的 Bean 中的构造器注入
关于 Spring 的动态语言支持,有一点非常重要需要注意。即,您目前无法为由动态语言支持的 bean 提供构造器参数(因此,由动态语言支持的 bean 不支持构造器注入)。为了使对构造器和属性的这一特殊处理完全清晰,以下代码和配置的组合将无法工作
package org.springframework.scripting.groovy
import org.springframework.scripting.Messenger
// from the file 'Messenger.groovy'
class GroovyMessenger implements Messenger {
GroovyMessenger() {}
// this constructor is not available for Constructor Injection
GroovyMessenger(String message) {
this.message = message;
}
String message
String anotherMessage
}
<lang:groovy id="badMessenger"
script-source="classpath:Messenger.groovy">
<!-- this next constructor argument will not be injected into the GroovyMessenger -->
<!-- in fact, this isn't even allowed according to the schema -->
<constructor-arg value="This will not work" />
<!-- only property values are injected into the dynamic-language-backed object -->
<lang:property name="anotherMessage" value="Passed straight through to the dynamic-language-backed object" />
</lang>
实际上,这个限制并没有它最初看起来那么重要,因为 setter 注入是绝大多数开发者青睐的注入风格(至于这是否是一件好事,我们改日再讨论)。
Groovy Bean
本节描述了如何在 Spring 中使用 Groovy 定义的 bean。
Groovy 首页包含了以下描述
“Groovy 是一个针对 Java 2 平台的敏捷动态语言,它具有许多像 Python、Ruby 和 Smalltalk 等语言中深受人们喜爱的特性,并通过类似 Java 的语法提供给 Java 开发者。”
如果您从头开始阅读本章,您已经看到了一个示例关于 Groovy 动态语言支持的 bean。现在考虑另一个示例(再次使用 Spring 测试套件中的示例)
package org.springframework.scripting;
public interface Calculator {
int add(int x, int y);
}
以下示例使用 Groovy 实现了 Calculator
接口
package org.springframework.scripting.groovy
// from the file 'calculator.groovy'
class GroovyCalculator implements Calculator {
int add(int x, int y) {
x + y
}
}
以下 bean 定义使用了 Groovy 中定义的计算器
<!-- from the file 'beans.xml' -->
<beans>
<lang:groovy id="calculator" script-source="classpath:calculator.groovy"/>
</beans>
最后,以下小型应用程序演练了前面的配置
package org.springframework.scripting;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
Calculator calc = ctx.getBean("calculator", Calculator.class);
System.out.println(calc.add(2, 8));
}
}
运行上述程序产生的输出(毫不意外地)是 10
。(有关更多有趣的示例,请参阅动态语言展示项目以获取更复杂的示例,或参阅本章后面的场景示例)。
每个 Groovy 源文件不能定义多个类。虽然这在 Groovy 中是完全合法的,但(可以说)这不是一个好的实践。为了保持一致的方法,您应该(Spring 团队认为)遵循每个源文件包含一个(公共)类的标准 Java 惯例。
使用回调定制 Groovy 对象
GroovyObjectCustomizer
接口是一个回调接口,允许您在创建 Groovy 支持的 bean 的过程中加入额外的创建逻辑。例如,此接口的实现可以调用任何必需的初始化方法、设置一些默认属性值或指定一个自定义的 MetaClass
。以下列表显示了 GroovyObjectCustomizer
接口定义
public interface GroovyObjectCustomizer {
void customize(GroovyObject goo);
}
Spring Framework 实例化由 Groovy 支持的 bean 的一个实例,然后将创建的 GroovyObject
传递给指定的 GroovyObjectCustomizer
(如果已定义)。您可以使用提供的 GroovyObject
引用做任何想做的事情。我们预计大多数人都想使用此回调设置自定义的 MetaClass
,以下示例展示了如何实现
public final class SimpleMethodTracingCustomizer implements GroovyObjectCustomizer {
public void customize(GroovyObject goo) {
DelegatingMetaClass metaClass = new DelegatingMetaClass(goo.getMetaClass()) {
public Object invokeMethod(Object object, String methodName, Object[] arguments) {
System.out.println("Invoking '" + methodName + "'.");
return super.invokeMethod(object, methodName, arguments);
}
};
metaClass.initialize();
goo.setMetaClass(metaClass);
}
}
在 Groovy 中进行元编程的全面讨论超出了 Spring 参考手册的范围。请参阅 Groovy 参考手册的相关部分或在线搜索。有很多文章涉及这个主题。实际上,如果您使用 Spring 命名空间支持,使用 GroovyObjectCustomizer
非常容易,如下例所示
<!-- define the GroovyObjectCustomizer just like any other bean -->
<bean id="tracingCustomizer" class="example.SimpleMethodTracingCustomizer"/>
<!-- ... and plug it into the desired Groovy bean via the 'customizer-ref' attribute -->
<lang:groovy id="calculator"
script-source="classpath:org/springframework/scripting/groovy/Calculator.groovy"
customizer-ref="tracingCustomizer"/>
如果您不使用 Spring 命名空间支持,您仍然可以使用 GroovyObjectCustomizer
功能,如下例所示
<bean id="calculator" class="org.springframework.scripting.groovy.GroovyScriptFactory">
<constructor-arg value="classpath:org/springframework/scripting/groovy/Calculator.groovy"/>
<!-- define the GroovyObjectCustomizer (as an inner bean) -->
<constructor-arg>
<bean id="tracingCustomizer" class="example.SimpleMethodTracingCustomizer"/>
</constructor-arg>
</bean>
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"/>
您也可以在与 Spring 的 GroovyObjectCustomizer 相同的位置指定一个 Groovy CompilationCustomizer (例如 ImportCustomizer )甚至是一个完整的 Groovy CompilerConfiguration 对象。此外,您可以在 ConfigurableApplicationContext.setClassLoader 级别为您的 bean 设置一个带有自定义配置的公共 GroovyClassLoader ;这也会导致共享的 GroovyClassLoader 使用,因此在有大量脚本化 bean 的情况下建议这样做(避免每个 bean 都有一个独立的 GroovyClassLoader 实例)。 |
BeanShell Bean
本节介绍如何在 Spring 中使用 BeanShell bean。
BeanShell 主页包含以下描述:
BeanShell is a small, free, embeddable Java source interpreter with dynamic language features, written in Java. BeanShell dynamically runs standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.
与 Groovy 不同,基于 BeanShell 的 bean 定义需要一些(少量)额外的配置。Spring 中 BeanShell 动态语言支持的实现很有趣,因为 Spring 会创建一个 JDK 动态代理,该代理实现了 <lang:bsh>
元素的 script-interfaces
属性值中指定的所有接口(这就是为什么您必须在属性值中至少提供一个接口,因此在使用基于 BeanShell 的 bean 时要面向接口编程)。这意味着对基于 BeanShell 的对象的每一次方法调用都会通过 JDK 动态代理调用机制。
现在我们可以展示一个完全可用的示例,使用一个基于 BeanShell 的 bean,它实现了本章前面定义的 Messenger
接口。我们再次展示 Messenger
接口的定义:
package org.springframework.scripting;
public interface Messenger {
String getMessage();
}
以下示例展示了 Messenger
接口的 BeanShell“实现”(这里我们松散地使用这个术语):
String message;
String getMessage() {
return message;
}
void setMessage(String aMessage) {
message = aMessage;
}
以下示例展示了定义上述“类”(再次强调,这里我们非常松散地使用这些术语)的“实例”的 Spring XML:
<lang:bsh id="messageService" script-source="classpath:BshMessenger.bsh"
script-interfaces="org.springframework.scripting.Messenger">
<lang:property name="message" value="Hello World!" />
</lang:bsh>
有关您可能想要使用基于 BeanShell 的 bean 的一些场景,请参见场景。
场景
在脚本语言中定义 Spring 管理的 bean 可能受益的场景多种多样。本节描述了 Spring 中动态语言支持的两种可能用例。
脚本化 Spring MVC Controller
可以受益于使用动态语言支持的 bean 的一类是 Spring MVC controller。在纯粹的 Spring MVC 应用中,Web 应用的导航流很大程度上由封装在 Spring MVC controller 中的代码决定。随着 Web 应用的导航流和其他表示层逻辑需要更新以响应支持问题或不断变化的业务需求,通过编辑一个或多个动态语言源文件并立即看到这些更改反映在正在运行的应用状态中,可能会更容易地实现任何此类所需的更改。
请记住,在 Spring 等项目倡导的轻量级架构模型中,您通常的目标是拥有一个非常薄的表示层,而应用的所有核心业务逻辑都包含在领域层和服务层类中。将 Spring MVC controller 开发为动态语言支持的 bean,使您可以通过编辑和保存文本文件来更改表示层逻辑。对这些动态语言源文件的任何更改(取决于配置)都会自动反映在由动态语言源文件支持的 bean 中。
为了实现动态语言支持的 bean 自动“拾取”任何更改,您必须启用“可刷新 bean”功能。有关此功能的完整处理,请参见可刷新 Bean。 |
以下示例展示了一个使用 Groovy 动态语言实现的 org.springframework.web.servlet.mvc.Controller
:
package org.springframework.showcase.fortune.web
import org.springframework.showcase.fortune.service.FortuneService
import org.springframework.showcase.fortune.domain.Fortune
import org.springframework.web.servlet.ModelAndView
import org.springframework.web.servlet.mvc.Controller
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
// from the file '/WEB-INF/groovy/FortuneController.groovy'
class FortuneController implements Controller {
@Property FortuneService fortuneService
ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse httpServletResponse) {
return new ModelAndView("tell", "fortune", this.fortuneService.tellFortune())
}
}
<lang:groovy id="fortune"
refresh-check-delay="3000"
script-source="/WEB-INF/groovy/FortuneController.groovy">
<lang:property name="fortuneService" ref="fortuneService"/>
</lang:groovy>
脚本化 Validator
Spring 应用开发的另一个领域,可能会受益于动态语言支持的 bean 所提供的灵活性,那就是验证。使用松散类型的动态语言(可能还支持内联正则表达式)来表达复杂的验证逻辑,可能比使用常规 Java 更容易。
同样,将 validator 开发为动态语言支持的 bean,使您可以通过编辑和保存简单的文本文件来更改验证逻辑。任何此类更改(取决于配置)都会自动反映在正在运行的应用的执行中,并且无需重启应用。
为了实现动态语言支持的 bean 自动“拾取”任何更改,您必须启用“可刷新 bean”功能。有关此功能的完整和详细处理,请参见可刷新 Bean。 |
以下示例展示了一个使用 Groovy 动态语言实现的 Spring org.springframework.validation.Validator
(有关 Validator
接口的讨论,请参见使用 Spring 的 Validator 接口进行验证):
import org.springframework.validation.Validator
import org.springframework.validation.Errors
import org.springframework.beans.TestBean
class TestBeanValidator implements Validator {
boolean supports(Class clazz) {
return TestBean.class.isAssignableFrom(clazz)
}
void validate(Object bean, Errors errors) {
if(bean.name?.trim()?.size() > 0) {
return
}
errors.reject("whitespace", "Cannot be composed wholly of whitespace.")
}
}
附加细节
这最后一节包含一些与动态语言支持相关的附加细节。
AOP — 通知脚本化 Bean
您可以使用 Spring AOP 框架来通知脚本化 bean。Spring AOP 框架实际上并不知道一个被通知的 bean 可能是一个脚本化 bean,因此您使用(或打算使用)的所有 AOP 用例和功能都适用于脚本化 bean。通知脚本化 bean 时,您不能使用基于类的代理。您必须使用基于接口的代理。
您不仅限于通知脚本化 bean。您还可以用支持的动态语言编写切面本身,并使用这些 bean 来通知其他 Spring bean。不过,这确实是动态语言支持的高级用法。
作用域
如果不是立即显而易见,脚本化 bean 可以像任何其他 bean 一样设置作用域。各种 <lang:language/>
元素上的 scope
属性允许您控制底层脚本化 bean 的作用域,就像控制常规 bean 一样。(默认作用域是singleton,与“常规”bean 相同。)
以下示例使用 scope
属性将一个 Groovy bean 定义为原型作用域:
<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang https://www.springframework.org/schema/lang/spring-lang.xsd">
<lang:groovy id="messenger" script-source="classpath:Messenger.groovy" scope="prototype">
<lang:property name="message" value="I Can Do The RoboCop" />
</lang:groovy>
<bean id="bookingService" class="x.y.DefaultBookingService">
<property name="messenger" ref="messenger" />
</bean>
</beans>
lang
XML schema
Spring XML 配置中的 lang
元素用于将用动态语言(如 Groovy 或 BeanShell)编写的对象作为 bean 公开到 Spring 容器中。
这些元素(以及动态语言支持)在动态语言支持中得到了全面介绍。有关此支持和 lang
元素的完整详细信息,请参见该部分。
要使用 lang
schema 中的元素,您需要在 Spring XML 配置文件顶部添加以下前言。以下片段中的文本引用了正确的 schema,以便您可以使用 lang
命名空间中的标签:
<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang https://www.springframework.org/schema/lang/spring-lang.xsd">
<!-- bean definitions here -->
</beans>