2011-08-15 19 views
0

我在應用程序中嘗試保存.properties文件時出現奇怪的行爲。 該應用程序是使用maven和Spring 3.0.5的JSF 2.0。當保存屬性文件時,Tomcat 7正在重新加載應用程序

試圖保存文件的代碼是這樣的:

public class ControladorPopupConfiguracaoImportadorNFe extends ControladorPopup{ 

private static final long serialVersionUID = 1L; 
private ModeloPopupConfiguracaoImportadorNFe modeloPopup; 
private ControladorPopupAlerta popupAlerta; 

@Override 
public void submit() {   
    Properties propriedades=new Properties();  
    definirPropriedades(propriedades);  
    if(salvar(propriedades)){ 
     this.fechar();  
     popupAlerta.abrir("As novas configurações foram salvas e já estão em uso!"); 
    }else 
     popupAlerta.abrir("Não foi possível salvar as novas configurações."); 
} 

private void definirPropriedades(Properties propriedades) {  
    propriedades.setProperty("recuperadorNFe.usaSsl",modeloPopup.getUsaSsl().toString()); 
    propriedades.setProperty("recuperadorNFe.porta",modeloPopup.getPorta()); 
    propriedades.setProperty("recuperadorNFe.urlImap",modeloPopup.getUrl()); 
    propriedades.setProperty("recuperadorNFe.usuario",modeloPopup.getUsuario()); 
    propriedades.setProperty("recuperadorNFe.senha",modeloPopup.getSenha()); 
    propriedades.setProperty("recuperadorNFe.nomeDaCaixa",modeloPopup.getCaixaEntrada()); 
    propriedades.setProperty("recuperadorNFe.diretorioDeArmazenamento",modeloPopup.getDiretorioDeArmazenamento()); 
    propriedades.setProperty("recuperadorNFe.caixaDestino",modeloPopup.getCaixaDestino()); 
    propriedades.setProperty("recuperadorNFe.horarioRecuperacao",modeloPopup.getHorarioRecuperacao());  
} 

private synchronized boolean salvar(Properties propriedades) { 
    try {   
     FileOutputStream outputStream=new FileOutputStream(modeloPopup.getArquivo());   
     propriedades.store(outputStream, "SEM COMETÁRIOS");   
     System.out.println("!!!!!!!!!!!!! - - - "+outputStream.getFD().toString()+" - - - !!!!!!!!!!!!!!");   
     outputStream.close();   
     return true; 
    } catch (Exception e) {    
     e.printStackTrace(); 
    }  
    return false; 
} 

@Override 
public void setModelo(ModeloComponenteBasico modelo) { 
    modeloPopup=(ModeloPopupConfiguracaoImportadorNFe) modelo; 
    super.setModelo(modelo); 
} 

public ControladorPopupAlerta getPopupAlerta() { 
    return popupAlerta; 
} 

public void setPopupAlerta(ControladorPopupAlerta popupAlerta) { 
    this.popupAlerta = popupAlerta; 
}} 

創造類ControladorPopupConfiguracaoImportadorNFe對象的春天文件是這樣的:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
    scope="singleton"> 
    <property name="locations" value="classpath:../propriedades/recuperadorNFe.properties" /> 
</bean> 


<bean id="controladorPopupConfiguracaoImportadorNFe" class="com.hrgi.ui.controladores.popups.ControladorPopupConfiguracaoImportadorNFe" 
    scope="request"> 
    <property name="modelo" ref="modeloPopupConfiguracaoImportadorNFe"/> 
    <property name="popupAlerta" ref="controladorPopupAlerta"/> 
</bean> 

<bean id="modeloPopupConfiguracaoImportadorNFe" class="com.hrgi.ui.modelo.ModeloPopupConfiguracaoImportadorNFe" 
    scope="session"> 
    <property name="visivel" value="false"/> 
    <property name="caixaDestino" value="${recuperadorNFe.caixaDestino}"/> 
    <property name="caixaEntrada" value="${recuperadorNFe.nomeDaCaixa}"/> 
    <property name="diretorioDeArmazenamento" value="${recuperadorNFe.diretorioDeArmazenamento}"/> 
    <property name="horarioRecuperacao" value="${recuperadorNFe.horarioRecuperacao}"/> 
    <property name="porta" value="${recuperadorNFe.porta}"/> 
    <property name="senha" value="${recuperadorNFe.senha}"/> 
    <property name="url" value="${recuperadorNFe.urlImap}"/> 
    <property name="usaSsl" value="${recuperadorNFe.usaSsl}"/> 
    <property name="usuario" value="${recuperadorNFe.usuario}"/> 
    <property name="arquivo" value="#{propriedadesImportador.file}"/>  
</bean> 

<bean id="propriedadesImportador" class="org.springframework.core.io.ClassPathResource" 
    scope="request"> 
    <constructor-arg name="path" value="../propriedades/recuperadorNFe.properties"/> 
</bean> 

,這是什麼發生在tomcat:

... 
15/08/2011 15:57:47 com.hrgi.persistencia.cadastro.conversores.ConversorPessoa carregarBeansDeContato 
AVISO: Lista de contatos está nula!! 
15/08/2011 15:57:58 org.apache.tomcat.util.http.Parameters processParameters 
INFO: Parameters: Invalid chunk '=' ignored. 
!!!!!!!!!!!!! - - - [email protected] - - - !!!!!!!!!!!!!! 
15/08/2011 15:58:02 org.apache.catalina.core.StandardContext reload 
INFO: Reloading Context with name [/cadastro] has started 
15/08/2011 15:58:02 org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
15/08/2011 15:58:02 org.springframework.context.support.AbstractApplicationContext doClose 
INFO: Closing Root WebApplicationContext: startup date [Mon Aug 15 15:57:10 BRT 2011]; root of context hierarchy 
15/08/2011 15:58:02 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons 
INFO: Destroying singletons in org.s[email protected]3445378f: defining beans [controladorPopupNovoCadastroPessoa,modeloPopupNovoCadastroPessoa,carregadorTipoPessoa,tipoPessoa,controladorPopupCadastroPessoa,modeloPopupCadastroPessoa,carregadorTipoCadastro,tipoCadastro,carregadorTipoBuscaPessoa,tipoBuscaPessoa,controladorPopupBuscaPessoa,modeloPopupBuscaPessoa,controladorSugestaoPessoa,carregadorPessoaEdicao,carregadorCidadesEnderecoEntrega,carregadorCidadesEnderecoFaturamento,carregadorItensSelectEmpresa,controladorRemocaoContato,controladorSelecaoTabelaContatos,linhaSelecionadaTabelaContato,contatoSelecionado,controladorRemocaoEmail,controladorSelecaoTabelaEmail,linhaSelecionadaTabelaEmail,controladorRemocaoTelefone,controladorSelecaoTabelaTelefone,linhaSelecionadaTabelaTelefone,controladorPopupNovoContato,modeloPopupNovoContato,controladorPopupNovoTelefone,modeloPopupNovoTelefone,controladorPopupNovoEmail,modeloPopupNovoEmail,entityManagerFactory,tipoLogradouroDao,ufDao,cidadeDao,empresaDao,cadastroDao,ramoAtividadeDao,contatoDao,emailDao,telefoneDao,funcionarioDao,funcaoDao,nomeApelidoFuncionarioDao,cepDao,bancoDao,febrabanDao,agenciaDao,tipoBancoDao,contaDao,visaoBuscaPessoaDao,visaoListagemEmpresaDao,visaoListagemAgenciaDao,validadorCPF,validadorCNPJ,validadorIE,validadorEmail,validadorSenhaNovo,validadorSenhaMudanca,validadorSenhaAtual,itensSelectUf,itensSelectTipoLogradouro,controladorPopupAlerta,modeloPopupAlerta,controladorPopupConfirmacao,modeloPopupConfirmacao,funcionarioLogado,empresaFuncionarioLogado,enderecoEmpresaFuncionarioLogado,coletorUsuarioLogado,funcionario,pessoaFisica,pessoaJuridica,enderecoEntrega,enderecoFaturamento,carregadorEnderecoFaturamento,carregadorEnderecoEntrega,controladorArmazenamentoFuncionario,controladorArmazenamentoPessoa,controladorArmazenamentoEmpresa,conversorFuncionario,conversorEmpresa,conversorPessoaFisica,conversorPessoaJuridica,conversorEnderecoEntrega,conversorEnderecoFaturamento,conversorContato,novaEmpresa,controladorPopupNovaEmpresa,modeloPopupNovaEmpresa,controladorPopupCadastroEmpresa,modeloPopupCadastroEmpresa,controladorPopupBuscaEmpresa,modeloPopupBuscaEmpresa,controladorSugestaoEmpresa,carregadorEmpresaEdicao,carregadorTipoBuscaEmpresa,tipoBuscaEmpresa,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.core.session.SessionRegistryImpl#0,org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.config.http.UserDetailsServiceInjectionBeanPostProcessor#0,org.springframework.security.filterChainProxy,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,daoAuthenticationProvider,detalhadorDeUsuarios,passwordEncoder,controladorPopupCadastroFuncionario,modeloPopupCadastroFuncionario,controladorPopupNovoCadastroFuncionario,modeloPopupNovoCadastroFuncionario,carregadorFuncoesFuncionario,controladorPopupMudancaSenha,modeloPopupMudancaSenha,controladorPopupBuscaFuncionario,carregadorFuncionarioEdicao,modeloPopupBuscaFuncionario,controladorSugestaoFuncionario,carregadorTipoBuscaFuncionario,tipoBuscaFuncionario,controladorPopupCadastroAgencia,modeloPopupCadastroAgencia,agencia,conversorAgencia,controladorArmazenamentAgencia,carregadorBancos,controladorPopupNovoCadastroBanco,modeloPopupNovoCadastroBanco,controladorPopupCadastroBanco,modeloPopupCadastroBanco,bancoOficial,itensSelectBancoFebraban,controladorArmazenamentoBanco,conversorBanco,controladorPopupCadastroConta,modeloPopupCadastroConta,conta,armazenadorConta,carregadorEmpresasComCNPJ,carregadorAgencias,controladorPopupConfiguracaoImportadorNFe,modeloPopupConfiguracaoImportadorNFe,propriedadesImportador,importadorNFe,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,organizador,recuperador,imap,conectorImap,movedorEmail,marshaller,conversorEndereco,conversorIdentificacao,conversorEmitente,conversorDestinatario,conversorProduto,formatadorDecimal,formatadorData,conversorICMS,conversorICMS00,conversorICMS10,conversorICMS20,conversorICMS30,conversorICMS40,conversorICMS51,conversorICMS60,conversorICMS70,conversorICMS90,conversorICMSPartilhado,conversorICMSST,conversorIPI,conversorPIS,conversorCOFINS,conversorImposto,conversorTotalizador,conversorItem,conversorTransportadora,conversor INFOrmacoesAdicionais,conversorTransporte,conversorFatura,conversorDuplicata,conversorCobranca,conversorNotaFiscal,formatadorString,geradorDigitoVerificador]; root of factory hierarchy 
... 

回答

1

當爲webapp設置<Context reloadable="true">時會發生這種情況。大多數IDE就像Eclipse一樣,默認情況下會這樣,只要webapp上下文資源發生變化,Tomcat就會重新加載(基本上是重啓)。這對於開發很有用。


除了具體問題,將文件保存到Web應用程序上下文中的Web應用程序運行時,確實是一個壞主意由於以下原因:

  1. 每當你重新部署WAR文件的所有更改會丟失和/或重新啓動服務器。
  2. 並非所有容器都會將部署的WAR擴展爲可寫的文件夾結構。

您應該將這些文件放在webapp外的固定文件系統路徑中,並將該路徑添加到webapp的運行時類路徑中。例如,/var/webapp/conf。您可以將外部路徑配置爲系統屬性,並且可以通過在Tomcat的/conf/catalina.propertiesshared.loader屬性中指定該路徑來將該路徑添加到類路徑。所有其他servlet容器支持類似的結構。只需在您的web應用程序的安裝手冊中正確記錄它。

+0

感謝BalusC,我會將屬性文件的路徑更改爲部署的應用程序路徑之外。 – brevleq

相關問題