2

Здраствуйте! Не знаю куда обратиться) Очень нужна помощь!

Ошибка:

javax.servlet.ServletException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'monApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: kz.mon.servlet.controllers.MainComponent kz.mon.servlet.controllers.AtmserviceApplication.mainComponent; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainComponent' defined in file [/home/camaro/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ATMService/WEB-INF/classes/kz/mon/servlet/controllers/MainComponent.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [kz.mon.servlet.controllers.MainComponent]: Constructor threw exception; nested exception is java.lang.NullPointerException com.vaadin.terminal.gwt.server.AbstractApplicationServlet.handleServiceException(AbstractApplicationServlet.java:999) com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:548) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


Мой основной класс

AtmserviceApplication.class

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.vaadin.Application;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Window;

@Component(value = "monApplication")
@Scope(value = "session")
public class AtmserviceApplication extends Application {

    @Autowired
    MainComponent mainComponent;

..........................................................

MainComponent.class

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.Tree;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;

@Component(value = "mainComponent")
@Scope(value = "session")
public class MainComponent extends CustomComponent {

(Ошибка когда пытаюсь подключить следующюю строчку)

    @Autowired
    SourceControllerInterface sourceController;

...............................................................................

SourceControllerImplementation.class

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.vaadin.addon.jpacontainer.JPAContainer;

@Component(value = "sourceController")
@Scope(value = "session")
public class SourceControllerImplementation implements
        SourceControllerInterface {
    public SourceControllerImplementation() {
    }

    @Resource(name = "atmModelProvider")
    private AtmModelProvider atmProvider;

    public String getATMContainer() {
        JPAContainer<ATM> container = new JPAContainer(ATM.class);
        System.out.println("AAAAAAAAAA");
        container.setEntityProvider(atmProvider);
        System.out.println(container.size());
        return "ХЛАБЫСЬ!";
    }
}

Спасибо заранее.

1
  • Could not instantiate bean class [kz.mon.servlet.controllers.MainComponent]: Constructor threw exception; nested exception is java.lang.NullPointerException NPE в конструкторе MainComponent - как выглядит конструктор этого класса?
    – yozh
    11 авг 2011 в 15:32

1 ответ 1

2

Всем спасибо, причина нашлась, проблема была в том, что запрос был в конструкторе, т.е. класс еще не заварился, а уже был запрос, поэтому и нуллпоинтер, вынес из класса MainComponent из конструктора в отдельный метод и над ним поставил @Postconstruct, и все стало нормально.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.