Spring Boot Difference with Date - spring-mvc

Upgraded my product from spring framework to spring boot. It is using json Parser from fasterxml.jackson. Unit tests having date comparison are failing now.
Expected time is
2098-12-31T00:00:00.000Z
but actual is
2098-12-30T15:00:00.000Z
My locale is Asia/Tokyo. I tried to change timezone in the mapper, currently showing Asia/Tokyo, to UTC but did not work.
Any help will be appreciated

Library I was using fasterxml.jackson 2.8.3 was not spring boot compatible. Not sure why though. I used another json parser and solve

Related

Tomcat 9 and Servlet API 2.5

My spring web application is using servlet api 2.5 along with spring framework 4. Its deployed in tomcat 9. Its working fine. I am not sure why tomcat is not complaining about it as it needs servlet api 4 as per documentation. Is it backward compatible or spring is doing some magic? Just for clarity We are using interfaces from servlet api 2.5 in our code which should not compile with servlet api 4. It is compiling because we are compiling with 2.5 but we are expecting it to fail at runtime in tomcat. Thanks
Are you using methods/classes that no longer exist in servlet spec 4? There isn't magic - it's downward compatible. If you tried to run, for example, AsyncEvent code in Tomcat 5.5 (servlet spec 2.4) then yes, you'd have a problem. But running old code on a new server - without using things that have totally changed or disappeared - is rarely a problem.
EDIT
You said that the "old" code has:
Map parameterMap = request.getParameterMap();
This is still valid if not best practice. With newer compilers you may get a warning from the compiler that you are not using generics but it is still valid. And since the Javadocs from that time say:
Returns: an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
So your old code must be casting the keys as a String and the values as a String[] - just like the newer code that would be:
Map<String, String[]> parameterMap = request.getParameterMap();
Both versions will compile in recent versions of the compiler though, again, you may get warnings with the code that doesn't take advantage of generics.
The key is the use of generics - the <String, String[]> part. It's clearer code when using generics and the compiler can help with issues. With the non-generics version you could have tried to cast the key in the map to any object. It would compile but at runtime you'd likely get a ClassCastException.
From the perspective of Tomcat it's still returning the same thing.
Is that clearer?

Using spring-kafka as configuration framework

My question may sound weird, but still.
Is it possible to use spring-kafka only as a configuration framework - like parsing application.properties or application.yaml and instantiate consumer and producer without Spring Boot Autoconfiguration facilities? Basically, minimal sprinkles of spring and spring-kafka for just public static void main application.
Thank you
Not sure what you mean with a "configuration framework", but from your description it sounds like you still want to use spring-kafka. So, there is nothing wrong to have a PropertySourcesPlaceholderConfigurer to resolve #Value annotations for configuration properties against your application.properties in the #PropertySource.
See docs for more info: https://docs.spring.io/spring/docs/5.2.4.RELEASE/spring-framework-reference/core.html#beans
See sample in Spring for Apache Kafka docs how to configure spring-kafka without Spring Boot: https://docs.spring.io/spring-kafka/docs/2.4.3.RELEASE/reference/html/#with-java-configuration
So, you need to combine spring-kafka feature with that #PropertySource + #Value for parsing configuration properties.
Essentially you are going to do whatever Spring Boot does for you ;-)

How to integrate spring-security.xml file into spring boot ? using Annotation base only

I have searched and didn't find any helpful solution that's why i am going to post this question.
Actually i have spring boot project which is completely configure based upon 'Annotation'.
Now for some reason, i need to add spring-security into this project.
for that i am getting spring-security-XXX.xml file from other co-worker.
Now, i am thinking how can i wrote some Annotation which will automatically load that spring-serity-xxx.xml file into my current project environment without change any other part, so that i can achieve security feature as per spring-serity-xxx.xml file.
For example, #Configuration(classpath:spring-security-config.xml) something like, is it possible ?.
if it's possible then provide me completed list of configuration.
NOTE : security added to get OAuth integration.
Any Help Appreciate..!!
Use #ImportResource annotation.

encryption of the war using Spring

I hava met some problems .
I want to encrypt the war using Spring by a tool named ClassGuard ,but when I deploy it to Tomcat and started to launch it , some problems(seemed to be A fatal error has been detected by the Java Runtime Environment) arised .
have anyone used ClassGuard and met problems like this?
please help me...thanks in advance!
Although without the exception we can only speculate, the ClassGuard FAQ section clearly states that:
As of Version 1.5, ClassGuard supports Tomcat containers.
To use ClassGuard in combination with tomcat, you have to configure your web application for using the ClassGuard tomcat class
loader. This can be set in the context of the web application.
So make sure that:
You are using the latest stable version.
You are using the appropriate class loader.
A probably (although not sure if it is what you are after) easier way to discourage usage of your code would be through Obfuscation Tools such as these.

which jar contains org.springframework.util.MultiValueMap in spring2.5?

I am using spring2.5. and trying to implement a custom CommonsMultipartResolver for ajax upload.
After I submited form, I got following error:
org.springframework.web.util.NestedServletExceptio n: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.multipart.commons.CommonsF ileUploadSupport$MultipartParsingResult.getMultipa rtFiles()Lorg/springframework/util/MultiValueMap;
It seems that I need class org.springframework.util.MultiValueMap. But I can not find it anywhere in spring2.5.
Can you tell me which jar contains it?
thanks
It supposed to be in org.springframework.core...jar file, but such class does not exist in Spring 2.5
http://static.springsource.org/spring/docs/2.5.0/api/org/springframework/util/package-summary.html
It was added only in Spring 3.0.x
http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/util/package-tree.html
I think you may be mixing versions of spring jars, since the 2.5 version returns a regular Map as parameters to the getMultiPartFiles() method (javadoc). The 3.0.x version uses MultiValueMap (javadoc).
It's not the map type that is missing, but the method. Check that you are using spring-web version that matches the rest of your spring dependencies.

Resources