Spring Validation Framework without Annotations - spring-security

My requirement is to validate Class fields on the basis of external configuration file i.e xml. I dont want to use annotation as if I want to change some configuration, I will need to change class file which is not desirable. I assume this is implemented using Spring AOP, so there must be some namespace for external configuration in spring context xml file. Any help will be highly appreciated.

Check out the XML configuration section of the Hibernate Validator reference manual. It might work for your requirements.

Related

Vaadin #JavaScript for different builds

I use Vaadin #JavaScript annotation to load JavaScript files for my application. It works great but I would need different JavaScript loaded for differents builds.
The idea is to have something like these:
#JavaScript("url.from.properties.or.pom")
So for DEV I would get #JavaScript("https://example.com/test/js/embed.js") and for PROD #JavaScript("https://example.com/production/js/embed.js"). The script url value should be taken from application.properties or pom.xml.
I cannot figure out how to do it. I use Vaadin 8 with Maven and Spring Boot. Thank you in advance.
There's no direct support for what you want to do, but I can come up with three different solutions that you could consider.
Register a DependencyFilter that dynamically rewrites the dependency URL from the annotation depending on the situation.
Create separate Java classes for each case (with all the actual functionality in a shared super class). You can then have either runtime logic or use e.g. different Spring configurations to choose exactly which class to use.
Remove the #JavaScript annotation and instead call JavaScript.eval from onAttach to somehow dynamically inject the script you want.

Connect to Grails Datasource from Grails Plugin Command

I'm attempting to write a plugin for Grails that will automatically generate my domain classes based on special views that we're designing in our legacy database. I basically just want to save myself some time manually writing all the mapping stuff required to make the domain classes work.
Do I have access to the dataSource defined in the application.yml of the project from a custom ApplicationCommand implementation? If so, how do I pull it so I can open my connection to the database?
I found the answer here. The dataSource bean that is injected into regular artefacts can be accessed through the ApplicationContext like this:
def dataSource = applicationContext.getBean('dataSource')

How to use Grails Domain objects in a Java project?

I have a Grails application with outsourced (in a separate Grails Plugin) domain objects and would like to use the domain objects in a Java application.
If this is possible, how to do that?
Thanks
In order to use them as domain classes, you need GORM-plugin to be installed somehow in your java code. Without the plugin the domain classes lose their "active record" aspect and can be used only as POJOs.
I can barely imagine how to do that w/o lot of pain
You need to define your custom hbm.xml hibernate mapping files. See hibernate doc

Grails Plugin Development - override domain class

Plugins in Grails are great method to modularise an application.The documentation suggest to override the artifacts from the plugin in the application, which uses this plugin.
Is it realy the best approach?
Let's describe it by example: There is a domain class "org.User" defined in the plugin. The application overrides this domain class. If I use "grails run-app" then there are no warnings and it works. But Eclipse (GGTS) complains about "Invalid duplicate class definition of class org.User". For some developers it wouldn't matter, but I like the IDE helping on coding by stuf like "autocomplete".
At the end both classes are compiled an put on the java class loader. The application version of the class is loaded before the version of the plugin. The class resolver finds it first and that's why it works. Please correct me if I'm wrong at this point. Is it realy a good idea to have two versions of a class in one class loader?
What are the alternatives?
You can do like Spring Security Core plugin does, provide the User class as a template, so your application that use this plugin can choose between creating his own class or installing your default User class.
The plugin user template is here, and the script responsible to create this in the application is here.
You will need also a config value to know the class to use, and use it dynamic.
P.S: there are good security plugins like Shiro and Spring Security, maybe it's easier to check them instead of create your own.

StructureMap XML Configuration

I'm trying to figure out how to define the following StructureMap DSL in my web.config:
For(typeof(ILog<>)).HttpContextScoped().Use(typeof(LogFactoryWrapper<>));
Does the XML approach even support this more unusual type of declaration?
Thanks!
Did you try with:
<DefaultInstance PluginType="path.to.interface.ILog,assembly.withoutdll" PluggedType="path.to.implementation.Log,assembly.withoutdll" Scope="HttpContext" />
Jeremy Dmiller (the father of StructureMap) wrote in his blog:
As for the Xml configuration, it was going to be a near rewrite of the Xml configuration for StructureMap 3.0 and there wasn’t much demand for it. I’m happily open to pull requests if you want it for StructureMap 3.0, but it’s definitely going to be moved to a separate Nuget package because Xml support is not part of PCL.

Resources