Я получаю предупреждение от аннотированного метода инициализации PostConstruct

Я получаю это предупреждение от аннотированного метода инициализации @PostConstruct

18 шек. 2014 г., 14:46:10 аннотация javax.annotation.PostConstruct не может объявлять какие-либо проверенные исключения. Этот метод будет проигнорирован.

Итак, мой метод игнорируется, что мне нужно сделать, чтобы решить эту проблему?

package com.revir.managed.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;
import org.springframework.beans.factory.annotation.Autowired;

@ManagedBean(name = "pickListBean")
@ViewScoped
public class PickListBean implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private DualListModel<TrvrTani> tanis;

private DualListModel<TrvrIlac> ilacs;


int tanisize = 0;
String taniadi = null;
Long taniidp = null;
public Long getTaniidp() {
    return taniidp;
}

public void setTaniidp(Long taniidp) {
    this.taniidp = taniidp;
}

String tanikodu = null;

@Autowired(required=false)
private TrvrTaniDAO tanidao;

public TrvrTaniDAO getTanidao() {
    return tanidao;
}

public void setTanidao(TrvrTaniDAO tanidao) {
    this.tanidao = tanidao;
}

List<TrvrTani> sourcetani;
List<TrvrTani> targettani;

List<TrvrIlac> sourceilac;
List<TrvrIlac> targetilac;

@PostConstruct
public void init(){
    try {
        sourcetani = new ArrayList<TrvrTani>();
        targettani = new ArrayList<TrvrTani>();

        tanidao = new TrvrTaniDAO();
        List<TrvrTani> taniList = tanidao.findAll();
        for (TrvrTani tani : taniList) {
            Long taniid = tani.getTaniid();
            sourcetani.add(new TrvrTani(taniid, tani.getTaniadi(), tani
                    .getTanikodu()));
        }

        tanis = new DualListModel<TrvrTani>(sourcetani, targettani);

        sourceilac = new ArrayList<TrvrIlac>();
        targetilac = new ArrayList<TrvrIlac>();

        ilacdao = new TrvrIlacDAO();
        List<TrvrIlac> ilacList = ilacdao.findAll();
        for (TrvrIlac ilac : ilacList) {
            sourceilac.add(new TrvrIlac(ilac.getIlacid(), ilac.getIlacad(),
                    ilac.getBarkod(), null));
        }

        ilacs = new DualListModel<TrvrIlac>(sourceilac, targetilac);
    } catch (Exception e) {
        System.out.println("Hata mesajı : " +e);
        throw e;
    }
}


public DualListModel<TrvrIlac> getIlacs() {
    return ilacs;
}

public void setIlacs(DualListModel<TrvrIlac> ilacs) {
    this.ilacs = ilacs;
}

public DualListModel<TrvrTani> getTanis() {
    return tanis;
}

public void setTanis(DualListModel<TrvrTani> tanis) {
    this.tanis = tanis;
}


public void onTransferTani(TransferEvent event) {
    StringBuilder builder = new StringBuilder();
    for (Object item : event.getItems()) {
        builder.append(((TrvrTani) item).getTaniadi()).append("<br />");

        targetlist(tanisize, taniadi, taniidp, tanikodu);

    }

    FacesMessage msgtani = new FacesMessage();
    msgtani.setSeverity(FacesMessage.SEVERITY_INFO);
    msgtani.setSummary("Tanı Eklendi");
    msgtani.setDetail(builder.toString());

    FacesContext.getCurrentInstance().addMessage(null, msgtani);
}

public void targetlist(int tanisize, String taniadi, Long taniidp,
        String tanikodu) {

    tanisize = tanis.getTarget().size();
    System.out.println(" ************target*************  : "
            + tanis.getTarget().size());
    for (int h = 0; h < tanisize; h++) {

        /* elemanin adi, id si ve kodu */
        taniadi = tanis.getTarget().get(h).getTaniadi();
        System.out.println(" ************taniadi1*************  : "
                + taniadi);
        taniidp = tanis.getTarget().get(h).getTaniid();
        System.out.println(" ************taniid2*************  : "
                + taniidp);
        tanikodu = tanis.getTarget().get(h).getTanikodu();
        System.out.println(" ************tanikodu3*************  : "
                + tanikodu);
    }
}

public void onTransferIlac(TransferEvent event) {
    StringBuilder builder = new StringBuilder();
    for (Object item : event.getItems()) {
        builder.append(((TrvrIlac) item).getIlacad()).append("<br />");
    }

    FacesMessage msgilac = new FacesMessage();
    msgilac.setSeverity(FacesMessage.SEVERITY_INFO);
    msgilac.setSummary("İlaç Eklendi");
    msgilac.setDetail(builder.toString());

    FacesContext.getCurrentInstance().addMessage(null, msgilac);
}
}

person Burak    schedule 18.04.2014    source источник


Ответы (1)


Удалите throws Exception из метода инициализации. Используйте try catch, чтобы предотвратить создание каких-либо исключений. Как только вы удалите объявление исключения, компилятор покажет вам любые исключения, которые могут быть выброшены, поэтому добавьте сюда try catch.

person damian    schedule 18.04.2014
comment
Я добавил try catch, теперь я не получаю никаких исключений - person Burak; 18.04.2014