How do I access native java in freemarker? - freemarker

For example, I would like to do some manipulation and methods using the Math native java class.
How could I gain access to this?

You can call any public and static method of exposed beans to Freemarker. See a similar question here. Also see the documentation.

Related

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

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?

How does spring aop proxy object knows which advice to call

I kbow Proxy object extends the target class and overrides non final methods. My question is, when the proxy object overrides target method, what extra code it adds to target method that makes advice to get called? And how proxy knows when to call an advice,before, after etc?
What you are asking is a bit too broad since the code used is quite complex.
I'm not sure why do you want to know the exact implementation details but as starting point you should check how Spring AOP works:
https://docs.spring.io/spring/docs/5.1.x/spring-framework-reference/core.html#aop
Spring implements proxying by using CGLIB or the JDK depending the situation (i.e.: if you implement your beans using interfaces, Spring will try to use the JDK).
You can check the Proxying mechanisms here: https://docs.spring.io/spring/docs/5.1.x/spring-framework-reference/core.html#aop-proxying
From there you can search for the libraries and check the code used for proxying.
I hope this serves you as a starting point for your reasearch.

How to use Spring to back Freemarker "?new" built in?

Currently we have a number of classes that extend TemplateMethodModelEx which we construct using Spring and then inject into the Freemarker Configuration as shared variables so they are available as functions to all of our templates.
However, it would be nicer to have more fine grained control and make these methods available on demand in individual templates. One can instantiate them using the ?new built in, but internally that uses the general Java reflection mechanism for instantiating the class, and these models need to be constructed via Spring to get their dependencies.
In a perfect world, I'd like to make it so that the ?new built in use Spring to construct the class. It looks like to do that I would need to find a way to overload BeansWrapper.newInstance(Class, List) to use Spring, but I'm unclear on the best way to accomplish that.
Note that we are currently using Freemarker 2.3.23

ehcache restful service methods override/extend

my question may be vague to ask. I am trying to use ehcache restful service methods such as get or put. I am not sure how this works under hood, is there any way I can override these methods? I mean, get always looks up in cache, but I want to look up in database if not found in cache. I can implement this behavior by writing my own rest service methods, but is there anyway to use ehcache built-in rest functionality by overriding their methods or extend their methods to look up in database if not found in cache. Appreciate your help, thanks.

Creating mixin with Spring AOP Introductions

Could someone provide a sample code snippet that stitches two java interfaces using spring-aop introduction (mixin)?
I'm looking for AspectJ annotation style configuration. Also, the specific use case I have is to stitch a few java beans each implementing their own interfaces together. So, rather than having a delegate coded, if I could just get away by using Spring XML, it'd be awesome.
You can use #DeclareParents or <aop:declare-parents> to get the mixin behavior. For example,
#DeclareParents(value="service.*", defaultImpl=AuditRecorderDefaultImpl.class)
private AuditRecorder mixin;
will mixin all classes in the service package with the AuditRecorder interface automatically forwarding each method to AuditRecorderDefaultImpl.
You can see working examples of this from AspectJ in Action's downloadable sources. You can also see detailed explanation in Spring documentation.
A demo based on Spring in Action book 4th edition is here, the configuration is JavaConfig style with #ComponentScan

Resources