Вопрос

Кажется, что улавтер на мою фасоль не работает.

Это моя весной java конфигурация, springconfig.java:

@Configuration
@ComponentScan("com.xxxx.xxxxx")
public class SpringConfig {

    @Bean(name="VCWebserviceClient")
    public VCWebserviceClient VCWebserviceClient() {
        VCWebserviceClient vCWebserviceClient = new VCWebserviceClient();
        vCWebserviceClient.setSoapServerUrl("http://localhost:8080/webservice/soap/schedule");

        return vCWebserviceClient;
}
.

vcwebserviceClient.java:

@Component
public class VCWebserviceClient implements VCRemoteInterface {

    private String soapServerUrl;

    public String getSoapServerUrl() {
        return soapServerUrl;
    }

    public void setSoapServerUrl(String soapServerUrl) {
        this.soapServerUrl = soapServerUrl;
    }

    // Implemented methods...

}
.

Мое приложение.java:

ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
VCWebserviceClient obj = (VCWebserviceClient) context.getBean("VCWebserviceClient");

System.out.println("String: "+obj.getSoapServerUrl()); // returns NULL
.

Почему obj.getsoaAserververll () возвращается null?

Этот пример показывает, как он должен работать.

Это было полезно?

Решение

Экземпляр, возвращаемый VCWebserviceClient, не тот фактически используется вашим приложением.Это путь для весны, чтобы узнать, какой класс для улучшения.

Любой способ, для вас, используйте @Value ( http://docs.spring.io/spring/docs/3.0.x/reference/expressions.html )

@Component
public class VCWebserviceClient implements VCRemoteInterface {

    // spring resolves the property and inject the result
    @Value("'http://localhost:8080/webservice/soap/schedule'")
    private String soapServerUrl;

    // spring automatically finds the implementation and injects it
    @Autowired
    private MyBusinessBean myBean;

    public String getSoapServerUrl() {
        return soapServerUrl;
    }

    public void setSoapServerUrl(String soapServerUrl) {
        this.soapServerUrl = soapServerUrl;
    }

    // Implemented methods...

}

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top