0

当我的应用程序尝试保存 .properties 文件时,我的应用程序出现了奇怪的行为。该应用程序是使用 maven 和 Spring 3.0.5 的 JSF 2.0。

尝试保存文件的代码是这样的:

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 类对象的 Spring 文件是这样的:

<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.
!!!!!!!!!!!!! - - - java.io.FileDescriptor@671ca33b - - - !!!!!!!!!!!!!!
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.springframework.beans.factory.support.DefaultListableBeanFactory@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
...
4

1 回答 1

1

这将在<Context reloadable="true">为 webapp 设置时发生。大多数 IDE (如 Eclipse)默认情况下都会这样做,因此只要 webapp 上下文资源发生更改,Tomcat 就会重新加载(基本上:重新启动)。这对开发很有用。


除了具体问题之外,由于以下原因,在 webapp 运行时将文件保存到 webapp 上下文中确实是一个坏主意:

  1. 每当您重新部署 WAR 文件和/或重新启动服务器时,所有更改都会丢失。
  2. 并非所有容器都会将部署的 WAR 扩展为可写的文件夹结构。

您应该将这些文件放在 webapp 外部的固定文件系统路径中,并将该路径添加到 webapp 的运行时类路径。例如,/var/webapp/conf。您可以将该路径从外部配置为系统属性,并且可以通过在shared.loaderTomcat 的/conf/catalina.properties. 所有其他 servlet 容器都支持类似的结构。只需将其正确记录在您的 webapp 的安装手册中即可。

于 2011-08-15T20:03:33.263 回答