2012-12-03 2 views
2

Spring MVC 포틀릿을 사용하고 있는데 문제가 있습니다. 하나의 빈을 가지고있는 동안 내 애플 리케이션이 제대로 작동합니다. 아래에 또 다른 빈을 추가하고 싶다면 오류가 발생하고 있습니다.필드의 자동 연결 실패 예외

오류 로그는 여기에 있습니다.

ERROR [org.springframework.web.portlet.DispatcherPortlet] - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addSinifController': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.project.service.SinifService com.project.controller.AddSinifController.sinifService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySinifService' defined in file [/tmp/1-sample_BookCatalog/WEB-INF/classes/com/project/service/SinifService.class]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:280) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1011) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:543) 
    at 
... 

내 application-context.xml;

<context:annotation-config/> 

<context:component-scan base-package="sample.code.listing" /> 
<context:component-scan base-package="com.project.controller" /> 
<context:component-scan base-package="com.project.domain" /> 
<context:component-scan base-package="com.project.service" /> 

<bean 
    class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
    <property name="webBindingInitializer"> 
     <bean 
      class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"> 
      <property name="propertyEditorRegistrars"> 
       <list> 
        <ref bean="myPropertyEditorRegistrar" /> 
       </list> 
      </property> 
     </bean> 
    </property> 
</bean> 

<bean id="myPropertyEditorRegistrar" class="sample.code.listing.utils.MyPropertyEditorRegistrar"/> 

<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>content.Language-ext</value> 
     </list> 
    </property> 
</bean> 

<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" 
     value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/WEB-INF/jsp/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

내 AddSinifController은 여기에 있습니다 :

@Controller(value="addSinifController") 
@RequestMapping(value="VIEW") 
@SessionAttributes(types=Sinif.class) 
public class AddSinifController { 

    @Autowired 
    @Qualifier("mySinifService") 
    private SinifService sinifService; 

    public SinifService getSinifService() { 
     return sinifService; 
    } 

    public void setSinifService(SinifService sinifService) { 
     this.sinifService = sinifService; 
    } 

    private Logger logger = Logger.getLogger(AddSinifController.class); 

    @RenderMapping(params = "myaction=addsinif") 
    public String showAddSinifForm(RenderResponse response,ModelMap model){ 
     return "addSinifForm"; 
    } 

    @RenderMapping(params = "myaction=home") 
    public String showhome(RenderResponse response,ModelMap model) {  
     return "home";  
    } 

    @InitBinder 
    public void initBinder(WebDataBinder binder) { 
     binder.registerCustomEditor(Long.class, new LongNumberEditor()); 

    } 
    @ModelAttribute("sinif") 
    public Sinif getCommandObject(){ 
     return new Sinif("sinif"); 
    } 
    @ModelAttribute(value = "myaction=siniflar") 
    public List<Sinif> getCommandObject2(){ 
     return sinifService.getSiniflar(); 
    } 
    @ActionMapping(params="myaction=addSinif") 
    public void addSinif(@ModelAttribute Sinif sinif, 
      BindingResult bindingResult, ActionResponse response, 
      SessionStatus sessionStatus){ 
      Kademe kademe = new Kademe("kademe"); 
      kademe.setId((long) 6); 
      sinif.setKademe(kademe); 
}   
      sinifService.addSinif(sinif); 
      response.setRenderParameter("myaction", "addsinif"); 
      sessionStatus.setComplete(); 

     if(!bindingResult.hasErrors()){ 
      System.out.println("hata yok"); 
      sinifService.addSinif(sinif); 
      response.setRenderParameter("myaction", "addsinif"); 
      sessionStatus.setComplete(); 
     }else{ 
      response.setRenderParameter("myaction", "home"); 
     } 
    } 


} 

안부

+6

* SinifService * bean을 만드는 데 문제가 있으며 스택 추적에 원인이 포함되어 있지 않습니다. 예외의 원인을 추가하십시오. –

+1

문제는 XML에있는 것이 아니라 SinifService.java 주석 기본 구성에 있습니다. – bmichalik

+0

여기에'AddSinifController.java'를 게시 할 수 있습니까? 그리고''을 사용하면''를 사용할 필요가 없습니다. – SRy

답변

3

이 SinifService의 INTERF을 구현 같은 주석에게 클래스에

@Qualifier("mySinifService") 

주세요 에이스, 당신이 인스턴스 싶어요. 기본적으로, 여기에있는 문제는 AddSinifController 클래스에서 SinifService 인터페이스를 autowire하도록 Spring에게 요청할 때, Spring은 인터페이스를 구현하는 클래스가 두 개 이상있을 때 인스턴스화 할 인터페이스의 구현을 알지 못한다는 것입니다. @Qualifier 어노테이션을 제공함으로써 인스턴스화하려는 특정 bean을 참조하게됩니다.