Wednesday, February 24, 2016

Lettuce throws NoSuchMethodError at Spring Data Redis and Spring Session

I use NetBenas 8.0.2 and the bundled default web server GlassFish to make a web service. I decided to use Lettuce 3.4.1 to connect from my web service to Redis 3.0 for managing sessions. I use Spring Data Redis 1.6.4 and Spring Session 1.0.2, and set them up in "WEB-INF\applicationContext.xml" as following.
<bean class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"
p:host-name="localhost"/>
When I started the web service, I got the following exception at the start-up.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory#0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()Ljava/util/Set;
The cause of this exception java.lang.NoSuchMethodError is that GlassFish has loaded its own old Guava 1.3 of C:\Program Files\glassfish-4.1\glassfish\modules\guava.jar instead of the web application's packaged recent Guava 1.8 and Lettuce tries to call the new method newConcurrentHashSet() since Guava 1.5, which doesn't exist in Guava 1.3 installed with GlassFish.
I fixed this problem by adding a new file, "WEB-INF/glassfish-web.xml" with the next content,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD 
GlassFish Application Server 3.1 Servlet 3.0//EN" 
"http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <class-loader delegate="false"/>
</glassfish-web-app>
This enables you to load your own packaged jars first before GlassFish loads its own jars.

Tuesday, February 16, 2016

Enable Broadcom BCM57780 after installing Ubuntu Server 14.04.2

When you install Ubuntu Server 14.04.2 on Dell Vostro 430, the ethernet interface is not recognized in the phase of "Detect network hardware" with the following message.
[!] Configure the network
No network interfaces detected
No network interfaces were found. The installation system was unable to find a network
device.
You may need to load a specific module for you network card, if you have one. For this,
go back to the network hardware detection step.
The unrecognized ethernet interface on my Dell Vostro 430 is Broadcom Corporation NetLink BCM57780 Gigabit Ethernet. Despite this, just keep installing even though the network is disabled when the installation completes.
After the installation, log in to the system on the console with the physical keyboard and type in the next command to list all the network interfaces.
$ ifconfig -a
The option -a shows all the network interfaces even though some of them are disabled. This command prints on the console as following.
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:32 errors:0 dropped:0 overruns:0 frame:0
          TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2480 (2.4 KB)  TX bytes:2480 (2.4 KB)

p128p1    Link encap:Ethernet  HWaddr a4:ba:db:01:9d:f6
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16
The disabled ethernet interface is p128p1. Memorize it to type in while configuring the network.
Start editing /etc/network/interfaces with the next command using vi.
$ sudo vi /etc/network/interfaces
Add the last two green lines to the file as follows.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto p128p1
iface p128p1 inet dhcp
Reboot the system with the following command.
$ sudo reboot
Now the system is connected to the network.