Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 字段自动关联失败,异常_Spring_Hibernate_Model View Controller_Javabeans_Portlet - Fatal编程技术网

Spring 字段自动关联失败,异常

Spring 字段自动关联失败,异常,spring,hibernate,model-view-controller,javabeans,portlet,Spring,Hibernate,Model View Controller,Javabeans,Portlet,我正在使用SpringMVCPortlet,我遇到了一个问题。我的应用程序在有一个bean时工作正常。如果我想在下面添加另一个bean,则会发生错误 错误日志在这里 ERROR [org.springframework.web.portlet.DispatcherPortlet] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean

我正在使用SpringMVCPortlet,我遇到了一个问题。我的应用程序在有一个bean时工作正常。如果我想在下面添加另一个bean,则会发生错误

错误日志在这里

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 
...
我的应用程序-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>

content.Language-ext

我的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");
        }
    }


}
@Controller(value=“addSinifController”)
@请求映射(value=“VIEW”)
@SessionAttributes(类型=Sinif.class)
公共类AddSinifController{
@自动连线
@限定词(“mySinifService”)
私服;
公共SinifService getSinifService(){
返回sinifService;
}
公共无效设置SinifService(SinifService SinifService){
this.sinifService=sinifService;
}
专用记录器=Logger.getLogger(AddSinifController.class);
@渲染映射(params=“myaction=addsinif”)
公共字符串showAddSinifForm(RenderResponse响应,ModelMap模型){
返回“addSinifForm”;
}
@渲染映射(params=“myaction=home”)
公共字符串showhome(RenderResponse响应,ModelMap模型){
返回“家”;
}
@InitBinder
公共绑定器(WebDataBinder绑定器){
binder.registerCustomEditor(Long.class,新的LongNumberEditor());
}
@模型属性(“sinif”)
public Sinif getCommandObject(){
返回新的Sinif(“Sinif”);
}
@ModelAttribute(value=“myaction=siniflar”)
公共列表getCommandObject2(){
返回sinifService.getsiniferal();
}
@动作映射(params=“myaction=addSinif”)
public void addSinif(@modeldattribute Sinif Sinif,
BindingResult BindingResult,ActionResponse响应,
会话状态(SessionStatus){
Kademe Kademe=新Kademe(“Kademe”);
"长"6号,;
西尼夫·塞特卡德梅(卡德梅);
}          
sinifService.addSinif(sinif);
响应。setRenderParameter(“myaction”、“addsinif”);
sessionStatus.setComplete();
如果(!bindingResult.hasErrors()){
System.out.println(“hata yok”);
sinifService.addSinif(sinif);
响应。setRenderParameter(“myaction”、“addsinif”);
sessionStatus.setComplete();
}否则{
响应。setRenderParameter(“myaction”、“home”);
}
}
}

关于

给出相同的注释

@Qualifier("mySinifService")

要实例化的实现SinifService接口的类。基本上,这里的问题是,当您要求Spring在AddSinifController类中自动连接SinifService接口时,当您有多个类实现您的接口时,Spring不知道要实例化接口的哪个实现。通过给出@Qualifier注释,您指的是要实例化的特定bean。

创建SinifService bean时出现问题,堆栈跟踪不包含原因。添加异常原因。问题不在XML中,而是在SinifService.java注释库配置中。您可以在此处发布
AddSinifController.java
吗?当您使用
时,您不需要使用
。您好,我添加了AddSinifController。将这一行添加到您的XML中: