小编mat*_*tus的帖子

使用@PropertySource注释时@Value未解析.如何配置PropertySourcesPlaceholderConfigurer?

我有以下配置类:

@Configuration
@PropertySource(name = "props", value = "classpath:/app-config.properties")
@ComponentScan("service")
public class AppConfig {
Run Code Online (Sandbox Code Playgroud)

我有财产服务:

@Component 
public class SomeService {
    @Value("#{props['some.property']}") private String someProperty;
Run Code Online (Sandbox Code Playgroud)

当我想要测试AppConfig配置类时,我收到错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String service.SomeService.someProperty; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'props' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' 
Run Code Online (Sandbox Code Playgroud)

该问题记录在SPR-8539中

但无论如何我无法弄清楚如何配置PropertySourcesPlaceholderConfigurer 以使其工作.

编辑1

这种方法适用于xml配置

<util:properties …
Run Code Online (Sandbox Code Playgroud)

configuration spring

56
推荐指数
6
解决办法
9万
查看次数

如何$项目将ObjectId投影到mongodb聚合中的字符串值?

是否有一个我可以在聚合函数中使用的运算符来获取字符串而不是ObjectId作为响应?

db.something.aggregate([ {$match: {'property': {$exists:true}} }, {$project: {stringId: '$_id.???'}}])
Run Code Online (Sandbox Code Playgroud)

mongodb mongodb-query aggregation-framework

25
推荐指数
2
解决办法
2万
查看次数

param:JSP中的隐式EL(表达式语言)对象

如果我有以下网址怎么办: servlet.jsp?myparam=myvalue

这两个EL应该返回输出"myvalue",但实际上我不明白为什么?:

${param.values["myparam"]["0"]}
${param.values.myparam[0]}
Run Code Online (Sandbox Code Playgroud)

jsp el

6
推荐指数
1
解决办法
2万
查看次数

Spring MVC mvc:资源位置属性

伙计我也有加载静态资源的问题.

我想我已经准备好了一切.但我不明白mvc:resources的location属性.它是为了什么?

如果我的位置VAADIN/themes/theme/...(在几个子文件夹,图像,css,js)下我的静态资源应该是什么位置和映射属性的正确值?

我在配置中有以下内容:

<mvc:resources location="/VAADIN/" mapping="/VAADIN/**"/>
Run Code Online (Sandbox Code Playgroud)

它不起作用.我想日志的以下部分是相关的:

17:15:02.897 [http-8080-2] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#6': no
 URL paths identified
Run Code Online (Sandbox Code Playgroud)

我收到HTTP状态404,例如http://127.0.0.1/VAADIN/themes/theme/css/style.css

spring spring-mvc

3
推荐指数
1
解决办法
8878
查看次数