Wednesday, August 19, 2015

Spring Integration JUG Notes



I recently attended a local Java User's Group on Spring Integration, on June 25, 2015.

Sam Alexander, the Enterprise Architect with Healthesystems was the presenter.  He was a very knowledgable and engaging speaker.  He was also very patient with the numerous questions that I asked. :-)

Although I have worked with multiple projects under the Spring umbrella since 2005 (Spring Core, Spring Data, Spring Security, Spring Web MVC), I had zero exposure to Spring Integration.

My notes from the presentation:

·         Spring Integration is in the same space as Apache Camel.  It is not an Enterprise Integration tool, it is really meant to help you write better code.

·         It uses a Messaging style architecture.  Here are some diagrams I drew during Sam’s presentation, converted from my handwritten notes to Visio.






·         Keys are immutable but values can change. 
·         There are many ways to construct a Message.

Channels

There are 2 types of channels: Pollable, Subscribable
·         Pollable – Point-to-point, buffer/queue capacity
·         Subscribable – No buffer, multiple endpoint receivers

Adapters

Adapters integrate with other systems.  They can talk with Streams, File, JMS, MongoDB, even Twitter.

Filters

Can use SpEL (Spring Integration Language), XPath, XML Schema for validation.

Transformers

Transformers handle serialization/deserialization somewhat differently than JMS.  There are numerous out-of-box Transformers.

Service Activators

Trigger a Service when a message arrives.

Gateway



Conclusion

Spring Integration is not an ESB (Enterprise Service Bus), not a BPM (Business Process Management) product.

Spring Integration is about Data Flow and Data Management, as opposed to ESBs which are for disparate applications.


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
 */
@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan("com.philiptenn.scholarship")
@PropertySource("classpath:application.properties")
@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.context.support.AnnotationConfigWebApplicationContext;
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();
        ctx.register(WebAppConfig.class);
        servletContext.addListener(new ContextLoaderListener(ctx));

        ctx.setServletContext(servletContext);

        Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
                new DispatcherServlet(ctx));
        servlet.addMapping("/");
        servlet.setLoadOnStartup(1);
    }

}


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


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

<web-app version="3.1"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         metadata-complete="false">

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

</web-app>


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:


        
        
        
          org.hibernate
          hibernate-core
          4.3.7.Final
          provided
        


According to wildfly.org 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:



    4.0.0

    jbosswildfly
    jbosswildfly
    war
    1.0
    jbosswildfly
  
    
        UTF-8
        1.8
        1.8
    
    
    
        
            javax
            javaee-api
            7.0
            provided
        
        
        
          org.slf4j
          slf4j-api
          1.7.12
          compile
        
        
          org.apache.logging.log4j
          log4j-slf4j-impl
          2.2
          compile
        
        
          org.apache.logging.log4j
          log4j-core
          2.2
          compile
        
        
        
          org.springframework
          spring-webmvc
          4.1.6.RELEASE
        
        
        
          org.hibernate
          hibernate-core
          4.3.7.Final
          provided
        
    


    
     
     
     
     
     openshift
     
        jbosswildfly
        
          
                org.apache.maven.plugins
                maven-war-plugin
                2.3
                
                    false
                    deployments
                  ROOT
                
            
        
      
    
  

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 user.name and user.email from the Global Git configuration.

From my Git Bash:

$ git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.name=Philip Tenn
user.email=ptenn@users.noreply.github.com

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.