Wednesday, April 22, 2015

UML Class Diagram

I'm building a scholarship application in my free time to continue learning and developing skills.

Here is my initial UML Class Diagram ... I created it using StarUML 2.1.2.  It's pretty simplistic right now.

Tuesday, April 21, 2015

IntelliJ IDEA, Spring Data Plugin, and recognizing @EnableJpaRepositories Annotation

Today I worked through an IntelliJ IDEA 14.1.1 (THE latest and greatest as of today, 4/21/2015) configuration issue that had me baffled.

I could not get IntelliJ to recognize Spring Data Repositories. 

I am using Spring JavaConfig for a Spring MVC Web Application and have the following code-based config class:

 * Spring JavaConfig Web Application Configuration for Spring MVC App.
 * @author Philip Tenn
@EnableJpaRepositories(basePackages = "com.philiptenn.scholarship.repository")
public class WebAppConfig extends WebMvcConfigurationSupport {

My issue was that the @EnableJpaRepositories annotation was not causing the IDE to recognize Spring Data JPA Repositories in my basePackage to be recognized as Spring-managed Repositories.

I have this working in other environments and could not figure out why.

I worked through the following JetBrains guide: Enabling JPA Support.  However, this did not enable IntelliJ to recognize the annotation.

Since I had this exact same project working in a different install of IntelliJ in a VM, I figured that it had nothing to do with my project and had to be something global.

Taking an educated guess, went to plugins.  Found a plugin that was disabled that looked like it could be relevant ... :-)

After enabling the Spring Data Plugin and restarting IntelliJ ... here was my result (SO HAPPY)!

Monday, April 20, 2015

Spring JavaConfig

I recently learned how to use Spring JavaConfig.  Unfortunately at work, we are still using XML-based Spring Configuration.

I wanted to dig into JavaConfig, so I started using it at home on personal development projects.

Just replaced the full contents of the web.xml file with the following:

package com.philiptenn.scholarship.init;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.servlet.DispatcherServlet;

 * @author Philip Tenn
public class Initializer implements WebApplicationInitializer {

    private static final String DISPATCHER_SERVLET_NAME = "dispatcher";

    public void onStartup(ServletContext servletContext)
            throws ServletException {
        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        servletContext.addListener(new ContextLoaderListener(ctx));


        Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
                new DispatcherServlet(ctx));


Now, my web.xml file is really skinny ...

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.1"

  <display-name>Spring MVC Application</display-name>


Having such a small XML file, that doesn't even contain a Servlet entry for the Spring MVC DispatcherServlet felt strange, like walking on a tightrope without a safety harness. However, everything seems to be working fine. :-)

Sunday, April 19, 2015

Spring Data JPA Setup

I'm having one of those "build your own lightsaber" moments.

At work, we are using Spring Data JPA and Hibernate.

Everything is nice and configured already, the Repositories, the TransactionManager, the EntityManagerRef.

With everything configured, it's pretty easy to just create a new Repository, write a couple of query methods following the nice findByFirstNameAndLastName  DSL provided by Spring Data, and inject the Repository into a Spring Service Bean.

The hard part is the configuration.  I'm trying to do that from scratch on a little personal project this weekend, to make sure I can do it.

Issue #1: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

Was getting this as a Runtime error immediately when deploying in JBoss Wildfly 8.2.0.Final.

In my Maven POM:


According to 8.2.0 Release Notes:

  • Hibernate 4.3.7.Final
Is supposed to be included as a component.

I could get around it by changing dependency scope from provided to compile and the error goes away, but that feels wrong.

I really don't want to package Hibernate into my WAR file when the Application Server I've selected (JBoss Wildfly 8.2.0.Final) provides it.  

Friday, April 17, 2015

Friday after-work coding

Woo-hoo, it's Friday, off work, I can code what I want.

I'm using Maven to build my OpenShift application.

My pom.xml:




Tuesday, April 14, 2015

IntelliJ IDEA and Git

Well, I've gotten a basic "Hello, world" Spring Web MVC Application running in JBoss Wildfly 8.2.0.Final set up with the initial Git Repo from OpenShift.

Now, I'm trying to do my first commit.  I've worked with Git through the Git Bash (msysgit), along with TortoiseGit and through Visual Studio / Git integration.

Even cloned, pushed, fetched to/from GitHub through these tools for .NET Projects.

However, this is my first experience using Git through IntelliJ IDEA on a pure Java project.

Initial take: for some reason IntelliJ is *not* picking up my and from the Global Git configuration.

From my Git Bash:

$ git config --list
rebase.autosquash=true Tenn

What I am seeing on the VCS commit window in IntelliJ:

I could (and did) manually type into this ComboBox my name and .  Just seemed strange it did not pick up from my Git config. 

Monday, April 13, 2015

Error running Wildfly 8.2.0.Final: Address localhost:9990 is already in use

Downloaded the latest JBoss Wildfly Final release (8.2.0.Final as of today, 2015-04-13).

Thought I would do some late-night personal coding now that the everyone else has gone to sleep.

Trying to run it through my IDE, immediately get an error:

Error running Wildfly 8.2.0.Final: Address localhost:9990 is already in use

I did some searching, and found the program that is competing with JBoss for port 9990 (which JBoss uses for its management endpoint by default).

C:\java\jdk1.7.0_76>netstat -a -b

  TCP         acer-predator:0        LISTENING

Aha ... NVidia's Network Service.  Now, I could change JBoss's port easy enough, but I like using out-of-box configuration.  I don't want to hack up my JBoss configuration to play nicely with my Windows Environment when I'll be working out of Linux as well ... best to make the Windows Environment work with my development projects.

Went into Windows Services, found NVIDIA Network Service, stopped it, set it to Manual.

Now Everything is actually Awesome! :-)  JBoss Wildfly starts up great!

OpenShift, Git and Maven

This is very interesting, it appears that by creating the OpenShift Application, it created a whole initial code layout (similar to a Maven Archetype), complete with POM file as the first commit in the git repository.

Here is what I saw when viewing the log for the cloned Git repository that OpenShift created:

I've always believed in trying to follow the best practices and standard approaches whenever I come into an environment.

For example, when doing Java Development, I follow the camelCase method naming approach; when doing C# development, I follow the PascalCase method naming approach.

In keeping with this tradition, I'm going to try and use Maven, seeing as how OpenShift coreated a pom.xml on my behalf. 

Sunday, April 12, 2015

OpenShift Client Setup

I just signed up for the free OpenShift account.

OpenShift is RedHat's foray into PaaS.

Since I've used JBoss as my JavaEE Application Server for the past 10 years at work (going all the way back to JBoss AS 4.2.2), it made sense for me to use as a platform for personal development projects.

They gave me 3 free small gears to use.  Ended up using my first one for a JBoss Wildfly 8.2.0.Final cartridge (community created).  I'm sure I'll need to use my second one for the database (debating between MySQL and Postgres).

It was easy to create the server instance.

Next step: gain access.

I followed the instructions for setting up OpenShift rhc Client Tools in a Windows Environment (I run a dual boot Fedora Core 21 / Windows 7).  Normally I do all my development out of Linux except .NET Development, and if/when I really start rolling on an OpenShift-deployed project, I'll probably switch back to Linux.

Step 1 - Install Ruby

Installed the latest Ruby x64 for Windows:

ruby 2.2.1p85 (2015-02-26 revision 49769) [x64-mingw32]

Step 2 - Install Git

Already had Git on my machine.

Step 3: Install and Configure the OpenShift gem

Ran into an error immediately after running rhc setup.

kernel_require.rb:54:in `require': cannot load such file -- dl/import (LoadError)

Upgraded net-ssh to 2.9.3.beta1 like the answer recommended, re-ran rhc setup, and it worked like a champ. 

Now that I'm all set up, next steps for me will include:

  1. Cloning (and understanding) the built-in Git Repository with the OpenShift Application.  I was surprised to read in their documentation that each OpenShift Application has its own Git Repo.  I had expected to create a Repo on GitHub and when I needed to deploy to OpenShift, I thought I would just drop a WAR or EAR file. 
  2. Setting up my Gradle Build.