Problema ApplicationContext

3 respostas
bestlinux

Pessoal,

Estou com um problema serio no Spring.

Estou tentando “setar” manualmente o contexto com o seguinte código:

ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"META-INF/minerva-client-app.xml", "META-INF/minerva-client.xml"});

Porém, ele acusa que os arquivo não existe etc. Quando troco para a seguinte linha:

ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"classpath*:META-INF/minerva-client-app.xml", "classpath*:META-INF/minerva-client.xml"});

Ele encontra os arquivos, porém, o arquivo minerva-client.xml utiliza um arquivo .properties que tem o seguinte conteúdo:

ws.minerva.url=http://webservices.sistemaindustria.org.br/minerva/services

minerva-client.xml

<bean id="estabelecimentoClient" class="br.org.cni.sindicato.ws.client.EstabelecimentoClient">
		<!-- property name="defaultUri"><value>http://webservices.sistemaindustria.org.br/minerva/services</value></property -->
		<property name="defaultUri"><value>${ws.minerva.url}</value></property>		
        <property name="marshaller" ref="marshaller"/>
        <property name="unmarshaller" ref="marshaller"/>
	</bean>

Quando rodo a aplicação, o seguinte erro é retornado:

java.net.URISyntaxException: Illegal character in path at index 1: ${ws.minerva.url}

O desenvolvedor que criou este webservice, me diz que o arquivo .properties não esta no meu classpath. Acho estranho isso, pois ja coloquei ele em todos os lugares. Segue em anexo uma imagem da estrutura do meu projeto:

Alguem tem ideia do que pode ser ?? :roll:

Obrigado ! :smiley:

3 Respostas

Diego.G.A

Tenta carregar o properties

property

guj.title.page=GUJ Page
<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/guj.properties" />
</bean>

depois utiliza a propriedade

<bean class="br.com.guj.Teste"> <property name="maxResults" value="${guj.title.page}"/> </bean>

bestlinux

Diego,

Não funcionou =/

Ate tentei trocar o codigo por este aqui embaixo:

public class Main {
  public static void main(String[] a) {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    BeanDefinitionReader reader = new PropertiesBeanDefinitionReader(bf);
    reader.loadBeanDefinitions(new ClassPathResource("context.properties"));

    Oracle oracle = (Oracle) bf.getBean("oracle");
    System.out.println("Meaning of life is " + oracle.defineMeaningOfLife());

  }
}

Mas da o mesmo erro:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Could not parse properties from class path resource [META-INF/context.properties]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/context.properties] cannot be opened because it does not exist
	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:270)
	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:215)
	at br.org.cni.sindicatos.ws.client.Main.main(Main.java:15)
Caused by: java.io.FileNotFoundException: class path resource [META-INF/context.properties] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:143)
	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:255)
	... 2 more

Alguem sabe o que pode ser ?? :roll:

Diego.G.A

coloca teu properties dentro de WEB-INF/classes/

e faz o seguinte

<bean id="propertyConfigurer" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:guj.properties" />
</bean>
Criado 24 de março de 2011
Ultima resposta 28 de mar. de 2011
Respostas 3
Participantes 2