Using the Spring Boot CLI (or Spring Initializr) to init a Jersey JAX-RS app

To use the Spring Boot CLI to init an app using Jersey JAX-RS apis, use:

spring init --build=maven --dependencies=jersey --packaging=jar SpringBootREST.zip

Unzip the packaged app, import into your IDE.

To get Spring Boot to initialize Jersey and see your annotated resources, you need to add a Spring component that extends Jersey’s ResourceConfig class, and call register() for each of your Resources (seems odd that you need to explicitly register your endpoints like this, as in a War deployed to a Servlet container they would get found automatically?)

[code]
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;

@Component
public class JerseyExampleConfig extends ResourceConfig {

public JerseyExampleConfig() {
register(SimpleResource.class);
}

}
[/code]

Additionally, each Resource endpoint class needs to be @Component annotated so Spring can managed them.

Your JAX-RS resources classes other than above are implemented as normal.

Installing Windows 8.1 guest on Linux Mint KVM

On my first attempt booting from the Windows 8.1 DVD to install as a guest in KVM, I got the initial Windows 8 splash screen, the DVD would spin for a few seconds but then spin down, and it would appear to be stuck at the logo screen, never reaching the spinning circle stage below the Windows icon.

There’s numerous posts of Windows 8 hanging at the logo screen, most of the conclusions seemed to be unless you didn’t have an error, just leave it until you get to the language selection dialog. I left mine about 10 minutes and got to the language dialog ok (I don’t remember a bare metal install taking that long before).

For my KVM vm settings, I left everything as defaults, apart from these changes based on numerous other posts on installing Windows 8 and 10 on KVM:

Processor: 1 CPU, and ‘copy host CPU configuration’

Disk: virtio disk bus, raw format, cache mode = node (not default)

Nic: virtio

Video: vga

After selecting ‘Custom install’ the ‘Where do you want to install Windows’ dialog says it could not find any drives. This is where you mount the virtio iso in the dvd for the vm, and then continue.

I hadn’t added a cd drive with the virtio iso to my vm before starting the install, and it looks like Virtual Machine Manager won’t let you add a device while the vm is running. Luckily, following as answer on this post, you can add a device on the fly with this command:

virsh attach-disk vmname /dev/sr0 hdc --type cdrom

I then loaded the virtio driver from this location on the mounted iso:

Next I got this rather cryptic error message:

"Windows is unable to install to the selected location. Error: 0x80300001."

Apparently this is a common error regardless of whether you’re installing Windows 8 in a VM or not. The quick explanation – unmount the virtio drivers iso, put back the install iso (or actual DVD) and refresh. Select partition (or create one) and continue. See here.

After completing all the prompts during install, success, Windows 8.1 virtualized using KVM on Linux Mint!

Post install, to get the virtio network card drivers install, mount the virtio iso disk, use the Control Panel/Drivers to view devices, pick the network card, then point to the NetKVM dir.

Next challenge, getting better video drivers installed (taking a look at Spice).

 

Spring Boot default app structure and component scan

I’m familiar with the Spring Framework’s concept of a ‘component scan’ to find its managed beans when the app initializes, but was looking for how to configure the package(s) for the component scan in a Spring Boot app.

Turns out (see docs here), by convention if your main app class annotated with @SpringBootApplication and is in a package with all your code in packages below this point, then those subpackages are scanned by default.

Here’s a simple Spring Boot app class:

[code]

package kh.simplespringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

[/code]

All packages below kh.simplespringboot in the example by default will be scanned for Spring components.

Arduino powered radio alarm clock – part 1

I had an idea to build an Arduino based radio alarm clock by re-purposing some other components I had lying around from other projects:

  • an Arduino Uno
  • an Adafruit 16×2 RGB LCD Pi Plate (for the display and control buttons)
  • an Adafruit Ultimate GPS breakout (for the time – what better way, albeit slightly over-engineered, to get the current time if not from GPS signals?)

The only part missing was an FM radio tuner. I was wondering how easy it would be to build a radio tuner from scratch (but not sure how I’d control it via the Arduino), so decided to take the easy approach to get started and use a TEA5767 based FM tuner on a chip. To make it even easier, I got a TEA5767 based breakout board for $5 on ebay that includes two jacks, one for an antenna and one for audio out.

Simon Monk has an Arduino library for the TEA5767 that has one function call to set the tuner frequency.

So far, pretty easy going. I have a start on combining the LCD to display time and GPS coords here. Now to add the radio library, add some controls from the Pi Plate buttons, and I’m almost there!

wp-1451374679689.jpg