Can someone tell me the exact use of jstl? Is it a good practice to use it to call dao methods? - jstl

I am working on hibernate and trying to use jstl but I don't know the purpose of using jstl. Should I use it code html or java code. Where it is used specifically?

Related

Implementing functions like #LocalPort in Spring Boot

I am contributing some framework and I am integrating it with Spring Boot. I want to create an annotation like #LocalPort that I made to use in testing. 😎
I found #LocalPort to be #Value in the end, but I don't think I can't use it because the annotation I'm making needs to be passed another value. In the end I think I should inherit ContextAnnotationAutowireCandidateResolver and either reimplement the getSuggestedValue(...) method or find another way. But I don't think this is the right way.
Is there another way to implement this? 🤔
For example,
#LocalSomePort(Protocol.HTTP) // Protocol.HTTPS
It was late, but I solved it by adding a custom BeanPostProcessor.

#WithMockUser and kotlin test

I'm a big fan of Kotlintest syntax and I'd like to know if it's possible to make it work with WebMvcTest. More particularly, I don't manage to annotate the test methods with #WithMockUser.
Does somebody know if it's feasible?
Thanks beforehand.
It's not something that is currently built into KotlinTest but there is a Spring module, so it should be fairly easy to create another extension that provides this.
This is the source for the spring module.
https://github.com/kotlintest/kotlintest/tree/master/kotlintest-samples/kotlintest-samples-spring

Spring-Boot Custom Repository

I have been reading about Spring Boot custom repository. I have dozens of blogs explaining how to implement those but none of them explained scenario when we actually need it?
I mean one example where we cannot live without custom repo. I mean if there is case of complex query, we can anyhow achieve it using #Query.
Please explain.
Lets say I want strongly typed query instead of #Query. I would create a custom repo, autowire EntityManager and use QueryDSL with it so I can use strongly typed references.
You can use it to extend the repository with other libraries that aren't part of Spring.
I find them useful when working with a program generator like jHipster. They keep your code separate from the generated code.
The xxxRepositoryCustom.java xxxRepositoryImpl will not be overwritten when the entities are re-generated by a dumb programmer (me.) The queries themselves have some complex logic that can not be expressed in a simple #Query

Is it possible to use Grails validation outside of Grails? How?

Grails has amazing validation; is it possible to use it independent of the Grails framework?
We have a Java/Groovy Camel-based web application we can't convert to a Grails application. I'd love to use the Grails-style validation with the declarative constraints but have been unable to successfully configure the application to work with Grails libraries without converting the whole thing.
The validation provided by Grails is just a wrapper around Spring's bean validation framework. Since Grails is open source you can take a look at how it's done and adapt it to your own needs. The best place to start looking is the GrailsDomainClassValidator and DomainClassGrailsPlugin to get an idea of how it's done. Another point of interest would be the #Validateable AST annotation.
As far as I know, and from what I can see in the source, there isn't a stand alone way to do this outside of a Grails project without writing your own adaptation/implementation.
You can use a external validation without problem. It is possible, for example, using a external "jar" (that do a validation) file on the "lib" folder of your Grails project. Through this way, you can use the API of this jar file. It's a simple way that you can use.

Use of Spring oxm

I am new to spring. I was looking into spring-oxm's XStreamMarshaller. I was hoping to find a way to convert my objects into xml using this. The spring site tells me clearly how to do it but it still needs me to add a XStream dependency in my POM. I don't understand what the use of spring-oxm is? If i had to add the xstream dependency anyway then i can directly use xstreams toXml operation and be done with it? I would really appreciate any help I could get in understanding the use of spring-oxm.
Thanks a lot in advance!
Spring provides a higher level abstraction for you by eliminating the scaffolding code you need to write. For e.g. in case of OXM you will be working with Marshaller and Unmarshaller abstractions irrespective of the underlying implementations uses (XStream, JAXB, Castor, XmlBeans etc). Moreover it lets you use DI for injecting marshalling/unmarshalling services to your own services. Another advantage is consistent exception hierarchy irrespective of the underlying implementation. All these are well explained on their reference documentation.
If you have very simple needs and doesn't already use Spring then I suggest you stick to JAXB that comes with JDK 6.

Resources