MyBatis Nullpointer related to #Autowired - nullpointerexception

I'm trying to write a program that will write to a mySql database using myBatis. I need to create a table containing id's and values. Currently I have a tag class, which holds these values, a tag dao interface, a tag xml implementation, and a main method. I am getting a nullpointer exception that I think is related to the #Autowired statement. If I use the #Autowired statement when I initialize the interface and the #Param statement when I write the interface, where in the code does my program know where to find the bean containing the information to find the xml file?

It depends how you are configuring Spring DI. I'd recommend configuring your application using Java configuration over XML, but it's personal preference. Take a look at the Spring documentation for Java configuration here.

Related

How to configure Jackson mapper

How can I globally configure json serializer for http4k? For example, snake case field names or formatting DateTime as ISO8601.
Since the ObjectMapper instance is private within ConfigurableJackson you cannot get at it after construction to do any configuration.
So you either need to construct your own direct instance of ConfigurableJackson and pass in a customized ObjectMapper or you need to subclass ConfigurableJackson with your own class. And then during the constructor, create an ObjectMapper (see example below) or intercept one being passed into your constructor and change its settings.
Whatever you do, be sure you do not break the http4k framework or anything else that might be using the same instance. You can see the defaults used by http4k declared in their source code:
object Jackson : ConfigurableJackson(ObjectMapper()
.registerModule(defaultKotlinModuleWithHttp4kSerialisers)
.disableDefaultTyping()
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(FAIL_ON_IGNORED_PROPERTIES, false)
.configure(USE_BIG_DECIMAL_FOR_FLOATS, true)
.configure(USE_BIG_INTEGER_FOR_INTS, true)
)
You can use code similar to above to create your own instance.
See this thread for some conversation about this topic: https://github.com/http4k/http4k/issues/183
You don't necessarily need to extend ConfigurableJackson - it's just that extending it is the most convenient way to do this (in our experience).
All configuration is done by tweaking the ObjectMapper instance which is injected into the ConfigurableJackson constructor - the ConfigurableJackson itself just provides the wrapper API around that mapper. The question is to do with standard configuration of Jackson, so you should seek answers to your specific questions (snake case etc) from the Jackson docs directly as http4k doesn't own that API.

Repository to execute Doctrine Dbal queries inside module

My goal is to be able to execute SQL queries from inside a PS 1.7.4.2 module. It is encouraged form the docs to use Doctrine Dbal services.
From the documentation:
Even if using old way to retrieve data is still valid
(Product::getProducts or through the webservice), we’d like to
introduce a best practice here: using a repository and get ride of the
Object model. This has a lot of advantages, you rely on database
instead of model and you’ll have better performances and control on
your data.
I don't think it respects PS philosophy if I put the repository class in src/Prestashop/Entity/Repository.So where to put the repository class?
Problem resolved by executing composer init inside module and mapping src in module to Foo namespace.
Then inside module files, you can access services from the container, i.e Doctrine services.
You can additionnaly define your own Repository classes as services and get them from the container.

Spring Data Rest Make an Entity Read Only by Default

I have an API exposed via Spring Data Rest which, for the most part, is read-only but which allows for updating of some properties via PATCH requests.
Is there any (I'm supposing Jackson) configuration at a global level that would essentially make an entity read only unless specific properties were annotated in some way.
I am familiar with the#JsonProperty(access = Access.READ_ONLY) Jackson annotation however would like to avoid having to annotate all read-only properties.
For example, given the class below only the field explicitly annotated would be writable. All other fields would be readable by default:
public class Thing{
private String fieldOne;
#JsonProperty(access = Access.READ_WRITE)
private String fieldTwo;
private String fieldThree;
// a lot of other properties
}
Failing any global configuration, is there anything that can be applied at the class level?
I am not aware of any way to globally set all attributes in a class to read only. Since version 2.6+ of FaserXML you can use the following annotation to at least defined the set of properties you would ignore and only allow for serialization. The following annotation would be used at the class level:
#JsonIgnoreProperties(value={ "fieldOne", "fieldThree"}, allowGetters=true)
It is not exactly what you are looking for, but arguably makes coding a little easier.

Mule DataMapper MEL custom functions or calling custom transformer

I have a question relating to the DataMapper component and extending the behaviour. I have a scenario where I'm converting one payload to another using the DataMapper. Some of the elements in my source request as strings (i.e. Male, Female) and these values need to be mapped to ID elements, known as enums in the target system. A DBLookup will suffice but because of the structure of enums (a.k.a lookup tables) in the target system I'd need to define multiple DBLookups for the values which need to be changed. So I'm looking to develop a more generic way of performing the mapping. I've two proposals, which I'm currently exploring
1) Use the invokeTransformer default function in to call a custom transformer. i.e.
output.gender = invokeTransformer("EnumTransformer",input.gender);
However, even though my transformer is defined in my flow
<custom-transformer name="EnumTransformer" class="com.abc.mule.EnumTransformer" />
Running a Preview in the DataMapper fails with the following error (in Studio Error Log)
Caused by: java.lang.IllegalArgumentException: Invalid transformer name 'EnumTransformer'
at com.mulesoft.datamapper.transform.function.InvokeTransformerFunction.call(InvokeTransformerFunction.java:35)
at org.mule.el.mvel.MVELFunctionAdaptor.call(MVELFunctionAdaptor.java:38)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1011)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
... 18 more
As the transformer is scoped to my flow and the datamapper is outside this scope do I assume it is now possible to invoke a custom transformer in a datamapper? Or do I require additional setup.
2) The alternative approach would be to use "global function". I've found he documentation in this area to be quiet weak. The functionality is referenced in the the cheat sheet and there is a [jira](
https://www.mulesoft.org/jira/browse/MULE-6438) to improve the documentation.
Again perhaps this functionality suffers from a scope issue. Questions on this approach is if anyone can provide a HOWTO on calling some JAVA code via MEL from a data mapper script? This blog suggests data mapper MEL can call JAVA but limits it's example to string functions. Is there any example of calling a custom JAVA class / static method?
In general I'm questioning if I am approaching this wrong? Should I use a Flow Ref and call a JAVA component?
Update
It is perfectly acceptable to use a custom transformer from the data mapper component. The issue I was encountering was a Mule Studio issue. Preview of a data mapping which contains a transformer does not work because the mule registry is not populated on the mule context as mule is not running.
In terms of the general approach now that I have realized the DB Lookup can accept multiple input parameters I can use this to address my mapping scenario.
Thanks
Rich
Try by providing complete class name

Google Guice: Singleton with xml deserialization support?

in my project I need a class which contains the project configuration.
The configuration must be loaded from a XML file and must be a singleton.
In Guice there is a singleton scope. Now I have to "overwrite" the singleton with the deserialized configuration.
Is this somehow possible?
Important: pelase do note that Guice was originally created to get rid of all these huge and ugly XML files used by another DI library for managing dependencies. In general, when using Guice, you should be able to -almost- completely remove any XML from your project.
But if you must, perhaps because the XML file is generated by something outside your control then consider these:
Keep your whole configuration object and create a Provider for it, and bind it in Singleton scope. But you'll have to perform deserialization by yourself.
Or if your configuration is simply made of (name, value) pairs, then you can use java.util.Properties whcih can be loaded from an XML file, then use Guice Names.bindProperties() API in one of your Modules.
Then you can directly inject each single property by using #Inject #Named.