The problem is that your validators can't access sessionFactory or any other interface to the database. I know that I can break some rules and instantiate a sessionFactory/session/connection directly inside the Validator, but I dislike to do wrong things consciously. So, I looking for alternatives.
By default, theLocalValidatorFactoryBeanconfigures aSpringConstraintValidatorFactorythat uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean.
I want to keep Trapo environment as simple as possible. I want that people just fire a command and all tests can run immediately: no setups, no database creation, no sql to run. Just one single command and trapo should do everything for you. Because of that, I start to isolate the test environment from the production one in order to use a different database instance (or even a different database vendor). To integrate the combo, I just call HSQLDB to the party. To avoid describe exactly what is HSQLDB, here is a quote from its homepage:
HSQLDB (HyperSQL DataBase) is the leading SQL relational database engine written in Java. It has a JDBC driver and supports a rich subset of ANSI-92 SQL (BNF tree format) plus many SQL:2008 enhancements. It offers a small, fast database engine which offers both in-memory and disk-based tables and supports embedded and server modes. Additionally, it includes tools such as a minimal web server, in-memory query and management tools (can be run as applets) and a number of demonstration examples.
FIRST, CONFIGURE MAVEN...
THIRD, REFACTOR YOUR TESTS...
Your tests should use SpringJUnit4Runner instead of the default one. So you have to put the following annotation in the test class:@RunWith(SpringJUnit4ClassRunner.class)So, do you want to run Trapo and see how it looks like?
Long time without posting here, but I have a good excuse. Last month I was moving to a new apartment! Nice move. Well, I'm trying to keep a pace while developing Trapo, but keep a pace is a quite difficult. Anyway, here are some screenshots for the current code on github.
Next week I will post more about the good, the bad and the ugly.I start Trapo as a google code project, but, because I'm trying to learn as much as I can, I move the code to github. That is the first time I use git and I have some minor problems (specially because I'm using Windows). Well, git is native to linux, but you can install on windows with msysGit. First I thought that git would be available in path, but it have its own bash. Then I follow github's instructions to create Trapo repository and some problems arise.
GIT CAN'T AUTHENTICATE0,21 seconds later google says me that I need to add the rsa key using ssh-add: >> ssh ~/.ssh/id_rsaBUT... ... the command outputs a error message: "could not open a connection to your authentication agent.". 0,09 seconds later google says me that I need to execute ssh-agent using the following command: >> exec ssh-agent bashwhere you can replace bash with the shell of your choice. Once you do this, you should be able to run ssh-add to load your key for that shell and so push code to github. Nice! Now you can clone Trapo from github or follow me there.I was looking for a way to run Trapo with a single command, maybe deploy it to Tomcat or another Servlet Container. But, I used to turn on the server, write some code and see the changes instantly on the browser. Re-deploy the whole application every time that I change something is a complete overkill. So, I found some blog posts saying that Jetty is a more lightweight container, and that can be started/embedded easily. Hum, for sure someone already have create a wheel that I can use.
HELLO, MAVEN JETTY PLUGINMaven Jetty Plugin is that wheel. You just need to configure it in your pom.xml and it could even scan periodically the file system to automatically restart the context. Because Jetty is fast (and also because Trapo still a tiny application), the restart is fast as hell. <plugin>