Get your InstrumentationLoadTimeWeaver recognized by LocalContainerEntityManagerFactoryBean

org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean is LoadTimeWeaverAware and as thus should be provided with such. Usually this would be done with a @Configuration, but then there is SPR-10856. In short: a LoadTimeWeaverAwareProcessor is provided before post processing the bean factory. This means that an @Bean inside a configuration class comes to load for load time weaving.

At least for Spring Boot there’s a solution. You can register the LoadTimeWeaver before startup:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
 
@SpringBootApplication
@EnableConfigurationProperties
public class Application {    
    public static void main(final String... args) {
        final SpringApplication springApplication = new SpringApplication(Application.class);
        springApplication.addListeners(new ApplicationListener<ApplicationPreparedEvent>() {
            @Override
            public void onApplicationEvent(final ApplicationPreparedEvent event) {
                event.getApplicationContext().getBeanFactory().registerSingleton(ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, new InstrumentationLoadTimeWeaver());
            }
        });
        springApplication.run(args);
    }
}

Be careful not to use a lambda, because there’s SPR-14109.

Anyway: This way byte code enhancement for JPA / Hibernate entities will work. Another solution would be build time byte code enhancement, as Vlad points out here: For Hibernate 5 and 4.

| Comments (0) »

10-Apr-16


Back to the roots: Playing with computer hardware…

Introduction

In January 2012 i bought a 27″ iMac 12,2 with a Intel Core i5 at 2,7Ghz which should have been a pretty decent and fast machine back then. The RAM can be easily upgraded in this thing which i did already back then to 16Gb for a fraction of the price Apple wants.

The machine came with OS X 10.6 “Snow Leopard” and shortly after migrating from my MacBook (i was using a MacBook back then for everything but the external display at home was annoying) i got a little disappointed. The iMac never was as fast as expected because the built-in, Apple branded Western Digital “WD1001FALS” was and is incredible slow (and I’m not the only one who thinks so). But the iMac was usable until OS X 10.8 “Mountain Lion” came out. From that point on i was afraid of every OS update coming out because booting took already ages.

I had all the RAM inside the machine for running VMs for testing purposes but i was afraid of restarting them. The Win 7 VM needed about 30 minutes to boot and the disk noise during that time was hardly bearable.

The problem with this iMac is not only that you have to open it through the front (removing the glas panel as well as the display) but also that it’s equipped with Apple branded disk having a custom firmware that reports the temperature through the power cable. If you replace it with a standard disk, the fans go haywire as the OS assumes something wrong. You can solve this with software but that seems too unstable for me.

German Apple reseller Gravis has it’s cBreeze module for fixing that but i wasn’t sure if i can buy it stand alone. Bringing my Mac to store would have forced me to delete my system upfront (totally out of question bringing a system into a store for days containing my personal life for the last 20 years).

Other World Computing also has a module available but i hesitated ordering until last week, when i read this tweet by Dominikus and i thought: What the heck… Let’s try this.

Read the complete article »

| Comments (1) »

22-Feb-16


Surface Pro 4 factory reset gets stuck at 7% (or 31%)

If you reset your Microsoft Surface Pro 4 to factory defaults for whatever reasons you might end up like me: In an endless boot loop or the reset process being stuck at 7% (or, if you choose to erase everything, at 31%), this solution worked for me:

  • Download the recovery image for your device and create an USB stick like described
  • Use it to boot your surface (press volume down, hold it, than power on)
  • Maybe the official way described here works for your. For me, it didn’t.
  • Instead i used “Troubleshoot > Advanced Options > Command Prompt.”. Start “diskpart”, enter “select disk system” and nuke your system drive with a “clean”
  • After that, you can reset and restore your device via the disk method which works for me at the point of writing

I needed to reset my Surface because i bound it to the wrong account. Happens. But i wonder how an average user would react to such a bad first experience. Even i was totally disappointed, which is sad, because the hardware really feels fabulous and the promise to run pretty much anything on this thing is great.

| Comments (27) »

09-Feb-16


Writing your own Spring Boot starter: wro4j-spring-boot-starter

I’ve been using Wro4j by Alex Objelean for more than 4 years now in a “classic” Spring application, see my post from January 2012 here. The tool has been immensely useful and stable. With my setup at dailyfratze.de, i can disable concatenation and minification during development and have optimized resources during production without much hassle.

Spring Boot is around for nearly 2 years now as well and i used it extensively, on my private projects, for my JUG and also in my company.

There are a lot of really useful starters out there, see the complete list here and i decided to add my own:

The wro4j-spring-boot-starter

Go to the Github project for a full description and short manual on how to use this. The binaries should be in Maven central under the following coordinates:

<dependency>
    <groupId>eu.michael-simons</groupId>
    <artifactId>wro4j-spring-boot-starter</artifactId>
    <version>0.0.7</version>        
</dependency>

I’ve been using the basic code now for 2 months, on the mentioned JUG site and in my company and as always, the Spring Eco system proved to be extremely stable and the people around extremely helpful.

I took the joy to inflect Springs check style settings onto my as Andy pointed out and wrote the starter under the spring-boot-starter-parent which is kinda brutal but gives a very welcome different view on code quality. Furthermore i tried to reach a good test coverage.

The starter will be used in my Spring Boot demo application as well as soon as i have fixed the AngularJS code which is a bit sensitive agains minification.

My favorite toy project, the AngularJS application biking2, based on Spring Boot, has now fully optimized web resources, see this commit.

Together with WebJars, Maven and application properties, Wro4j and now this starter are my preferred tools to stay in control of JavaScript dependencies without resorting to all kinds of package managers. Last year i hoped to be able to speak about that stuff at the JavaLand newcomer track but that didn’t work out. Maybe another conference or JUG and time.

Thanks a lot to my company ENERKO Informatik GmbH for providing the resources to work on that stuff.

Update: Thanks a lot Josh for adding this little starter to This Week in Spring – February 9th, 2016.

| Comments (0) »

02-Feb-16


Spring Boot based site and api for EuregJUG

Since March 2015 Stefan and i are building the EuregJUG Maas-Rhine, a cross-border, english-language Java User Group, located in Aachen. I’ve been blogging about regularly since then (see all posts here) and it’s developing quite well so far. We had 4 well visited talks, nice meetings in between and good conversations.

We noticed some problems, though, especially for managing events. Most Germans use Xing, Dutch and Belgians often use LinkedIn and there’s also Lanyard in the mix. Then there’s java.de running a calendar aggregate which needs an ics somewhere which would also be nice for other people. Our events are free, but for planning resources some kind of registration is a must.

In late 2015 i had the idea of building “our own JUG”. The first feedback was disappointing, though, so i postponed those ideas into my “end of the year” holiday:

  • Basic blogging (for annoucment like this), supporting Markdown or AsciiDoc as input
  • Handling of events (publishing as iCal, crossposting them to XING and Lanyard and certainly registration for those events)
  • Integration of our twitter feed
  • Maybe a mobile app based on JavaFX and Gluon?

Why doing this myself? I’m quite sure i can setup yet another WordPress project, stuff some plugins into it and be good to run, but the time needed would be the same or longer than doing this with the tools I “love”, namely Java inside the Spring eco system. So here we go:

After about 16 to 20 hours after christmas i had the basic site up and running with basic blogging and managing events (calendar, registration). At the moment i use a simple REST api with the awesome Paw as a generic REST client.

That sounds not to much, but the site is fully responsive, has nice database migrations, showcases Springs content negotiating and different views and last but not least, can run locally and without much ado inside “the cloud”, in this case as Stéphane told use in “Building cloud native apps with Spring Boot”.

We’ve made it into Joshs “This Week in Spring column for January 12th, 2016. Thanks a lot!

The site is live at euregjug.eu, the source code is fully available under an Open Source license at github and i’m gonna walk you through some of the interesting and useful parts:

Read the complete article »

| Comments (1) »

14-Jan-16