小编Nil*_*kar的帖子

@Value无需配置静态PropertySourcesPlaceholderConfigurer即可工作

我正在尝试不使用@Autowiring和Spring Environment类时了解@PropertySource批注的行为。我试图使用@Value在运行时从属性文件注入值。从我正在阅读的书中以及在线资源中,都需要具有一个静态bean-PropertySourcesPlaceholderConfigurer,以使其正常工作。但是对我来说,@Value也可以在没有PropertySourcesPlaceholderConfigurer静态bean的情况下使用。有人能指出我在这里发生的正确方向吗?可能是我缺少一些非常基本的东西。什么时候需要PropertySourcesPlaceholderConfigurer,什么时候不需要?

以下是我正在尝试的代码-

package com.nilaysundarkar.demos;

public class Person {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
Run Code Online (Sandbox Code Playgroud)

AppConfig.java-

package com.nilaysundarkar.demos;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

@Configuration
@PropertySource("classpath:/com/nilaysundarkar/demos/app.properties")
public class AppConfig {

    // This bean does not make any difference, or does it?
    /*@Bean
    public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer(){
        return new PropertySourcesPlaceholderConfigurer();
    }*/

    @Bean
    public Person person(@Value("${person.name}") String name){
        Person person = new Person();
        person.setName(name); …
Run Code Online (Sandbox Code Playgroud)

java spring

5
推荐指数
1
解决办法
926
查看次数

导入com.sun.jersey.api.client.ClientResponse的问题;

我有一个基本的java项目,其中我在我的java构建中使用外部导入了jersey-client-1.19.jar(使用eclipse).我正在尝试编写一个基本的泽西客户端来对Web服务进行RESTful调用.一旦我尝试导入ClientResponse类,eclipse就会抱怨 -

类型javax.ws.rs.ext.runtimedelegate $ headerdelegate无法解析.它是从所需的.class文件间接引用的.

Eclipse自动更正将我带到我的构建路径.但我没有运气解决这个问题.谷歌搜索但没有找到任何东西.

我错过了一些基本的东西.任何帮助表示赞赏.

java jax-rs jersey

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

标签 统计

java ×2

jax-rs ×1

jersey ×1

spring ×1