0

I am trying to serve static resources in the Spring mvc and drools project. To serve the static resources such as images ,css and js i tried to use the below:

1).

    <!-- Enables the Spring MVC @Controller programming model -->
       <mvc:annotation-driven />

   <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <mvc:resources mapping="/resources/js/**" location="/resources/js/"/>

2).

For scanning the components i used:

<!-- Scans within the base package of the application for @Components to configure as beans -->
   <context:component-scan base-package = "package-name" />

I have a form which loads after navigating to the new page , before using the 1 i am able to get the form loaded .

When i introduced 1 then i get the error as mentioned below:

HTTP Status 500 - org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [int] for value 'null'; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type

My questions::

Q1)I got one stackoverflow question stating the difference between the above two.I had not used annotation-driven earlier yet it was working as in the case mentioned.

Q2)I got this question which mentions both the 1 and 2 are required.

Q3)If i use only it gives 404 on form load page.

What is the thing that i am missing.

I am using spring mvc with spring 6 and drools 7.

EDIT:

I can see exception "java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type" in the console. Why is this only for primitive type only where as for String its not throwing exception.

Vikram
  • 332
  • 3
  • 16

1 Answers1

0

may be you are binding form object directly with your domain object.. so while binding value to variable of int type it is raising an exception..

instead of using primitive type use wrapper classes it works for null also

Navnath Adsul
  • 364
  • 3
  • 10
  • Yes , i am binding the value to variable of type int . I was going to edit the question a bit. I am able to see "java.lang.IllegalArgumentException: A null value cannot be assigned to a primitive type" error. So why is it finding a null value for primitive type? – Vikram Jan 02 '18 at 11:21
  • while submitting form instaed of sending null try to send 0(Zero) – Navnath Adsul Jan 02 '18 at 11:24
  • null is default value for any object and string is object – Navnath Adsul Jan 02 '18 at 11:25
  • instead of using primitive type use wrapper classes it works for null also – Navnath Adsul Jan 02 '18 at 12:03
  • I am not submitting a form rather i have a form in the jsp which while loading gives this exception. Yes i can use wrapper instead of primitive type int , but that would mean changing the attribute type so i am looking for some other way. – Vikram Jan 02 '18 at 12:27
  • If i disable ,the exception "org.springframework.core.convert.ConversionFailedException" is not there and the form loads properly – Vikram Jan 03 '18 at 08:47