如何将Spring配置文件设置为包? [英] How to set a Spring profile to a package?

查看:103
本文介绍了如何将Spring配置文件设置为包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将个人资料名称设置为整个包,但我不知道如何。如果哪里不容易,那么我必须使用 @Profile 注释标记包和子包中的每个类。

I want to set a profile name to a whole package and I don't know how. If where is no easy way then I have to mark every class in the package and sub packages with @Profile annotation.

< context:component-scan /> 标签不支持等属性个人资料所以我不知道。

<context:component-scan/> tag does not support attribute like profile so I have no idea.

推荐答案

您可以为以下内容设置个人资料:

You can set profile for:


  • Spring Beans XML文件 - 用于xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
       profile="your-profile">

    <context:component-scan base-package="your.package" />
</beans>




  • @Configuration Java配置类

    • @Configuration class for Java config
    • @Configuration
      @Profile("your-profile")
      @Componentscan("your.package")
      class AppConfig {
      }
      

      在每个组合中,您都可以使用组件扫描来查找特定包裹。

      In each of them you can use component scanning for your a particular package.

      这篇关于如何将Spring配置文件设置为包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆