Java 将SpringBoot属性Bean传递给其他项目中的类

Java 将SpringBoot属性Bean传递给其他项目中的类,java,spring,spring-boot,properties,Java,Spring,Spring Boot,Properties,我正在配置spring引导应用程序。所以我创建了一个属性bean类,如下所示: import javax.validation.constraints.NotNull; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframew

我正在配置spring引导应用程序。所以我创建了一个属性bean类,如下所示:

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@EnableConfigurationProperties
@PropertySource("classpath:/application.properties")
public class APPStaticProperties {

    @NotNull
    @Value("${dblog.system.name}")
    String db_logsystem_name;

    /**
     * @return the db_logsystem_name
     */
    public String getDb_logsystem_name() {
        return db_logsystem_name;
    }

    /**
     * @param db_logsystem_name the db_logsystem_name to set
     */
    public void setDb_logsystem_name(String db_logsystem_name) {
        this.db_logsystem_name = db_logsystem_name;
    }

}
我正在控制器类中创建一个对象:

@Autowired
APPStaticProperties appStaticProperties;

但是我想知道如何将这个对象传递给其他项目使用?因为我的代码流从控制器流向JSP,然后流向另一个项目中的类。我需要该类中可用的对象。老实说,在许多其他项目中也是如此!我想不出怎么做。也没有太多的示例可供参考。

您通常不会将@Configuration bean注入到其他Spring管理的bean中,因为它设置了供其他Spring管理的bean使用的配置

例如,由于您已经声明了@PropertySource,要在其他Spring托管中访问您的属性,意味着您可以使用@Value将属性插入到其他地方的代码中。您无需注入APPStaticProperties bean即可完成此操作