Pregunta

Parece que el setter en mi frijol no funciona.

Esta es mi configuración de java de primavera, 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;
}

The 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...

}

mi aplicación.java:

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

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

¿Por qué es obj.getSoapserververl () que regresa NULL?

Este ejemplo muestra cómo debería funcionar.

¿Fue útil?

Solución

La instancia devuelta por VCWebserviceClient no es la que realmente utiliza su solicitud.Es una forma de que la primavera sepa qué clase desea inscanciar.

de cualquier manera, para su problema, use el GeneracDicetArgCode ( http://docs.spring.io/spring/docs/3.0.x/reference/expressions.html )

@Value

@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...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top