Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @使用Spring的地图的价值注入?_Java_Spring_Spring Boot_Dependency Injection_Properties - Fatal编程技术网

Java @使用Spring的地图的价值注入?

Java @使用Spring的地图的价值注入?,java,spring,spring-boot,dependency-injection,properties,Java,Spring,Spring Boot,Dependency Injection,Properties,我们有一个java应用程序,它使用Spring(5.0.8)进行依赖项注入,但不受Spring Boot的管理。简单的@Value注入是通过在我们的Java配置类中使用它来实现的 final PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); StandardEnvironment myEnv = ne

我们有一个java应用程序,它使用Spring(5.0.8)进行依赖项注入,但不受Spring Boot的管理。简单的
@Value
注入是通过在我们的Java配置类中使用它来实现的

final PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
    StandardEnvironment myEnv = new StandardEnvironment();
    try {
        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst( new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
                                myEnv.getSystemProperties()));
        propertySourcesPlaceholderConfigurer.setPropertySources(propertySources);
}catch.....
ApplicationContext由启动

AnnotationConfigApplicationContext APPLICATION_CONTEXT =
            new AnnotationConfigApplicationContext(MyConfig.class)
然后我就可以开始使用属性作为

@Component
public class MyService {
    @Value( "${"myvalInSystemProperty"}")
    private String myval;

    ........
}
现在,我想使用SpEL-like添加一个
@Value
注入

@Component
public class MyService {

    @Value("#{${usermap}}")
    private Map<String, Map<String, String>> usermap;

    ........
}
我已将属性文件添加到propertySources中,如

propertySources.addLast( new ResourcePropertySource( "classpath:myMap.properties"));
我犯了这样的错误

Expression [#{{}] @0: No ending suffix '}' for expression starting at character 0: #{{}
不识别我的
@值
注入


有人能解释一下吗

我发现了问题所在。傻。在行尾需要反斜杠

我正在尝试跟随,但它对我根本不起作用。您是否只尝试了
@Value(${usermap}”)
?不建议使用TBH@Value,您应该使用类型安全配置属性。
Expression [#{{}] @0: No ending suffix '}' for expression starting at character 0: #{{}