ATEN
Dezembro 28, 2012, 1:29pm
#1
Estou produzindo uma aplicação em jsf no tomcat7 e estou tendo o seguinte erro
Caused by: java.io.NotSerializableException: java.util.PropertyResourceBundle
Todavia a aplicação funciona durante um tempo, mas para de funcionar de repente e da esse erro de cima.
Minha classe que eu pego o arquivo de mensagens esta serializada
public class MensagemProvider implements Serializable{
private static final long serialVersionUID = 1L;
private ResourceBundle bundle;
public ResourceBundle getBundle() {
if (bundle == null) {
FacesContext context = FacesContext.getCurrentInstance();
bundle = context.getApplication().getResourceBundle(context, "msg");
}
return bundle;
}
public String getValue(String key) {
String result = null;
try {
result = getBundle().getString(key);
} catch (MissingResourceException e) {
result = "???" + key + "??? not found";
}
return result;
}
}
Alguém já passou por isso ou sabe como consertar esse erro?
[]
Isso ajuda vc?
http://echo.nextapp.com/site/node/4059
Vc tá vendo que ele reclama que o “java.util.PropertyResourceBundle” não está Serializable e não a sua classe.
Não é recursivo o efeito. Todas os atributos contidos em uma classe Serializable também devem ser Serializable.
Isso é só um chute, mas tente colocar o transient no seu bundle (é bundle ein. heheh).
diz aí se deu certo.
abs
Veja a diferença no exemplo (o objeto NotSerializable (que seria equivalente ao seu Bundle) está transient e funciona ok… tirando o transient, ele tenta serializar e dá pau):
package br.pbing.serial;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Serial implements Serializable {
private static final long serialVersionUID = -1295773177935401165L;
private Integer id;
private String nome;
private Integer idade;
private transient NotSerializable not;
public static void main(String[] args) {
Serial obj = new Serial(1, "Paulo", 28, new NotSerializable(35));
String filename = "c:\\temp\\bing.ser";
System.out.println("antes de serializar");
System.out.println(obj);
write(obj, filename);
obj = null;
Serial newObj = read(filename);
System.out.println("apos desserializar");
System.out.println(newObj);
}
private static Serial read(String filename) {
Serial obj = null;
FileInputStream fis = null;
ObjectInputStream ois = null;
try {
fis = new FileInputStream(filename);
ois = new ObjectInputStream(fis);
obj = (Serial)ois.readObject();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return obj;
}
private static void write(Serial obj, String filename) {
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(filename);
oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public Serial(Integer id, String nome, Integer idade, NotSerializable not) {
super();
this.id = id;
this.nome = nome;
this.idade = idade;
this.not = not;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Integer getIdade() {
return idade;
}
public void setIdade(Integer idade) {
this.idade = idade;
}
public NotSerializable getNot() {
return not;
}
public void setNot(NotSerializable not) {
this.not = not;
}
@Override
public String toString() {
return "Serial [id=" + id + ", nome=" + nome + ", idade=" + idade
+ ", not=" + not + "]";
}
}
class NotSerializable {
private Integer teste;
public NotSerializable(Integer teste) {
super();
this.teste = teste;
}
public Integer getTeste() {
return teste;
}
public void setTeste(Integer teste) {
this.teste = teste;
}
@Override
public String toString() {
return "NotSerializable [teste=" + teste + "]";
}
}
ATEN
Dezembro 28, 2012, 2:48pm
#4
[quote=paulo.bing]Isso ajuda vc?
http://echo.nextapp.com/site/node/4059
Vc tá vendo que ele reclama que o “java.util.PropertyResourceBundle” não está Serializable e não a sua classe.
Não é recursivo o efeito. Todas os atributos contidos em uma classe Serializable também devem ser Serializable.
Isso é só um chute, mas tente colocar o transient no seu bundle (é bundle ein. heheh).
diz aí se deu certo.
abs[/quote]
E ai paulo,
Valeu cara, a princípio, tudo funcionando. Creio que era isso mesmo, fiquei meio confuso com essa exceção pois já estava bem acostumado a serializar os ManagedBeans no jsf e as classes no jpa e até estava acostumado tb a colocar transient em atributos destas classes, mas não imaginava que o “java.util.PropertyResourceBundle” não podia ser serializado.
Então coloquei “transient no bundle”!! hehe
private transient ResourceBundle bundle;
Vou passar o dia trabalho aqui na aplicação se este erro não ocorrer novamente, fecho o tópico aqui.
Mais uma vez, OBRIGADO pela atenção paulo
[]s
Legal… qqer coisa dá um toque.
abs