rod mclaughlin


Spring is here, O Spring is here... (06 feb 19...11 feb 19)

...life is skittles, and life is beer... 

 

Well, not quite.

The latest incarnation of the Spring Java Framework is called "Spring Boot", and they've done away with XML files. Hooray! These files were the main reason I wrote Clearcut, which doesn't need them:

https://github.com/pdxrod/clearcut

So I took some examples from the https://spring.io website, and incorporated them into

https://github.com/pdxrod/clearcut-spring

 

One of the samples is https://spring.io/guides/gs/consuming-rest/. It produces random quotes praising Spring.

One of the quotes says 'It embraces convention over configuration, providing an experience on par with frameworks that excel at early stage development, such as Ruby on Rails.' Really?

Each of these examples do something when you start them using Spring Boot. The Application.java file knows to load some of the other files, and it's a mystery how. There's nothing specific and procedural - it's all done with annotations and injection.

[Building a Hypermedia-Driven RESTful Web Service]

[Accessing data with MySQL]

[Consuming a RESTful Web Service]

[Creating a Batch Service]

But when you put them all together, Application only knows to do some of them, not all of them. So I had to tell it to do one of them - inserting a text file of users into the database - from https://spring.io/guides/gs/batch-processing/ - in GreetingController. This leads to a problem.

Hibernate depends on a table called "hibernate_sequence". Despite the fact that my person table has

| id | bigint(20) | NO | PRI | auto_increment |

and MySql auto-increments it if you use straightforward SQL inserts, if you use Hibernate by calling the Spring methods in PersonRepository, it uses the next_val column in the hibernate_sequence table to determine the id of the row it is inserting into the person table. Currently, the next_val column is set to 50, and the max(id) in the person table is 207, and the min is 48. See the problem? If Hibernate tries to insert a person row, it will try to use 51 as the id, and it's already taken. 

 

Does anyone know what this means?

greeting.add(linkTo(methodOn(GreetingController.class).greeting(name)).withSelfRel());

I tried googling 'withSelfRel' and can't find anything about it. The Spring source code is available at https://github.com/spring-projects/spring-framework, but withSelfRel isn't in it anywhere.

CORRECTION: it's here: https://docs.spring.io/spring-hateoas/docs/current/api/org/springframework/hateoas/core/LinkBuilderSupport.html

Link	withSelfRel()
Creates the Link built by the current builder instance with the default self rel.

So there you go.

 

In short, Spring is still Java. It requires less code than it used to, but this makes it less, not more, comprehensible. Thank God it got rid of those XML files though. (The samples come with pom.xml, but if you don't use Maven, you don't need it - you can use Gradle instead).

 

The title of this article is of course from Tom Lehrer's "Poisoning Pigeons in the Park" - https://www.youtube.com/watch?v=yhuMLpdnOjY.

 

This video by Brian Will explains in more general terms what's wrong with Object-oriented abstract programming: https://www.youtube.com/watch?v=QM1iUe6IofM.

 



Back
Portland London