Results 1 to 10 of 13

Thread: org.springframework.beans.BeanInstantiationExcepti on

Hybrid View

  1. #1

    Default org.springframework.beans.BeanInstantiationExcepti on

    Hi,

    I am trying to use "spring mobile" but I am having little success so far.

    I have made the following changes to my exisiting Spring 3.0 MVC project.

    POM - move

    spring-orm
    spring-context
    spring-beans
    spring-core
    spring-webmvc
    spring-web
    spring-jdbc
    spring-context-support

    org.springframework dependancies to 3.1.0.M1.


    change:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:mvc="http://www.springframework.org/schema/mvc" 
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
           
    <!--  Configures the @Controller programming model 
      --> 
      <mvc:annotation-driven />
        
    </beans>
    to

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:mvc="http://www.springframework.org/schema/mvc" 
           xmlns:device="http://www.springframework.org/schema/mobile/device"  
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/mobile/device http://www.springframework.org/schema/mobile/device/spring-mobile-device-1.0.xsd">
           <!--  When went to Spring 3.1 change line above to 3.1 -->
           
    <!--  Configures the @Controller programming model --> 
      <mvc:annotation-driven>
         <mvc:argument-resolvers>
            <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
         </mvc:argument-resolvers>
       </mvc:annotation-driven>
       
      <mvc:interceptors>
         <!-- On pre-handle, resolve the device that originated the web request -->
         <bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
      </mvc:interceptors>
     		
    </beans>
    In my controller I am trying to bind 'Device'

    Code:
     public String showUserPage(Principal principal,
    		@RequestParam(value="userid") Long userid,
                                 ModelMap model,
                                 Device device){

    but I am getting the following exception.

    org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.mobile.device.Device]: Specified class is an interface


    Any help greatly appreciated.

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Hmm. for some reason it seems the DeviceWebArgumentResolver is not getting picked up. Make sure you don't have any other AnnotationMethodHandlerAdapter beans floating around from your existing app. You might want to set a breakpoint on setCustomWebArgumentResolvers method of that class and see what gets injected there. Also I'd recommend referring to the lite-showcase sample app.
    Keith Donald
    Core Spring Development Team

  3. #3

    Default

    Thanks again,

    I have used the sample but as you correct pointed out I also had.

    Code:
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 
       
    
       <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
          <property name="messageConverters">
             <list>
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
             </list>
          </property> 
       </bean

    I have removed AnnotationMethodHandlerAdapter

    and used

    Code:
    <mvc:annotation-driven>
         <mvc:argument-resolvers>
            <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
         </mvc:argument-resolvers>
         <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
         </mvc:message-converters>
       </mvc:annotation-driven>
    This seems to work.

    I assume I can/should leave DefaultAnnotationHandlerMapping ?

  4. #4

    Default

    Also another question - does LiteDeviceResolver find the IPad as 'mobile' ?

  5. #5

    Default

    Realising the answer to my own question about IPADs (ie. will not be seen a 'mobile').

    I decided to move to WURFL.

    So I changed to:

    Code:
      <mvc:interceptors>
            <!-- On pre-handle, use WURFL to detect the device that originated the web request -->
            <bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor">
                <constructor-arg>
                	<!-- Inject a WurflDeviceResolver that populates its device repository from the specified file locations -->
                    <device:wurfl-device-resolver root-location="/WEB-INF/wurfl/wurfl-2.0.30.zip" patch-locations="/WEB-INF/wurfl/web_browsers_patch.xml" />
                </constructor-arg>		
            </bean>
        </mvc:interceptors>
    Having set up the zip and xml files.

    Changed:

    Code:
    public String showUserPage(Principal principal,
    		        @RequestParam(value="userid") Long userid,
                                        ModelMap model,
                                        Device device){
    file to

    import net.sourceforge.wurfl.core.Device;

    but I am now getting:

    org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [net.sourceforge.wurfl.core.Device]: Specified class is an interface


    My mvc:annotation-driven is:

    Code:
    <mvc:annotation-driven>
         <mvc:argument-resolvers>
            <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
         </mvc:argument-resolvers>
         <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
         </mvc:message-converters>
       </mvc:annotation-driven>
    I appear to have a binding issue.

    Again any help appreciated.

  6. #6
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    If you're using mvc:annotation-driven, you should not have DefaultAnnotationHandlerMapping or AnnotationMethodHandlerAdapter registered manually: this element registers them for you. Please refer to the wurfl-showcase sample and test it out and see how it's different then yours.

    Keith
    Keith Donald
    Core Spring Development Team

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •