Pages

Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, January 18, 2016

Auto-Wiring of Optional Beans with Spring using JSR-330

I've been using Spring for years and particularly like how little intrusive the framework is. For that reason I even still use the XML configuration option in order to have as little dependencies on the Spring framework as possible in my code. I also used to prefer explicit bean wiring over auto-wiring for the same reason, @Autowire is Spring annotation I tried to avoid; and also I have a tendency of being a control freak and didn't want some magic to determine my application setup. Not having a dependency on Spring is particularly important in my current project for various reasons. However, I'm over my control-freak attitude and with the arrival of JSR-330 I can get it all: Auto-wiring as well as JDK-only annotations/classes.

Thursday, September 17, 2015

Maven Shade Plugin with Spring Applications

I recently came across multiple projects that use the Maven Shade Plugin to package Java applications into one big jar. Not that I think this is a particularly good idea, in fact I believe it's a terrible idea that may lead to somewhat unpredictable results. However, you sometimes have to live with what's already in place...

When I started using Spring in my applications another downside of this approach emerged: While all the tests passed just fine the packaged application failed to even start throwing somewhat unexpected exceptions like this:

Saturday, September 27, 2014

Spring Data Neo4j Namespace Configuration Fails on Reload

I started a graph DB project using Neo4j a couple of weeks ago and decided to use Spring Data Neo4j to make my life easier. I got my app up without much hassle using the Spring Data Neo4j namespace configuration to configure my application in XML. This is quickly done with just 2 lines of XML:
<neo4j:config storeDirectory="/var/neo4j" base-package="graph.model" />
<neo4j:repositories base-package="graph.repositories"/>
Everything worked fine until I embedded my project in a larger Spring project which loads around 15 or so top level application context files for all the modules. Suddenly my configuration started throwing exceptions:

Thursday, November 28, 2013

Making Java Groovy

Manning Publications recently published "Making Java Groovy" by Ken Kouson so I went and bought it. I often buy books about topics I'm interested in and read them on the train to work to find out if the described technologies can help me with my current or future projects. I really like Manning books because they are usually a good mixture between tutorial/reference and just good introduction into technologies.

Working in an almost Java-only environment have been interested in Groovy for quite some time. Most Java developers know the problem: You have all kinds of libraries or at least code snippets that already capture your business logic. But if you want to run a quick script to make use of it, you either have to create a full blown Java app with all it's draw-backs, or go for some other scripting language that can do the trick with as little code as possible; for my quick-and-dirty scripts I usually resorted to one of bash, PHP or Perl. For more complicated tasks I bit the bullet I wrote Java app, bundled into one big jar with a myriad of command line parameters to be able to switch environment, figure out best settings and what not.

Friday, August 2, 2013

Nested Properties in Camel Routes

Apache Camel does not support Spring's nested properties in its configuration. I believe this feature is coming up, but at the time of writing this it's neither the case in the version we're running (2.9.1) nor in the current version (2.10.6 seemed totally broken, 2.10.5 also doesn't support it). This is generally unfortunate but in our case we're particularly missing this feature for the autoStartup property of a route.

We usually have groups of routes that are either started together or not at all. However, for e.g. debugging it would be nice to turn the whole group off and specific routes in the group on. This can be achieved relatively easily with a simple helper class that gets properties injected by Spring, hence supporting nested properties.

Thursday, August 1, 2013

Problem Storing Spring-Batch Job Parameters

We have been using Spring-Batch at inPowered for a while for relatively simple jobs with only a date parameter; MySQL is the backing store for meta data. When we added a job with a parameter of type string the job launcher had problems even getting the job started and the Spring-Batch UI displayed this error:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_PARAMS(JOB_INSTANCE_ID, KEY_NAME, TYPE_CD, STRING_VAL, DATE_VAL, LONG_VAL, DOUBLE_VAL) values (?, ?, ?, ?, ?, ?, ?)]; Data truncation: Incorrect datetime value: '1970-01-01 00:00:00' for column 'DATE_VAL' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1970-01-01 00:00:00' for column 'DATE_VAL' at row 1