Pokazywanie postów oznaczonych etykietą Spring. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą Spring. Pokaż wszystkie posty

poniedziałek, 1 lipca 2013

Message Driven Architecture with Spring

Here is a video introduction to MDA from Spring YouTube channel. It gives really good overview of basics including pooling, scheduling and task executing using Spring facilities. Also what is the value of this series presenter explains what are Enterprise Integration Patterns and their implementation in Spring Integration framework.



poniedziałek, 15 kwietnia 2013

Spring MVC - Create Sample Project with Eclipse and run it on JBoss 7


Project Setup
In this tutorial I’ll use Spring Tool Suite 3.1 and JBoss 7.1 Final but they are not required. You can use IDE and application server of your choice and configure it by yourself.

Follow the steps below:
       1.   Click Alt + Shift +N or File -> New and choose Project…


       2.   Spring -> Spring Template Project -> Next


       3.   Choose Spring MVC Project , click Next and confirm Yes


       4.   Insert your project name and default java package and click Finish



Your project will be created from predefined template. It is ready to use and we’ll test it on JBoss 7.

Setup Application Server in STS
You need to download JBoss from here and unpack it on your local file system. Then follow the steps:
       1.   Go to Servers tab in STS

       2.   Right click -> New -> Server


       3.   Find JBoss 7.1 in the tree. If it is not here click Download additional     adapters and install plugin for this concrete container.  Change server host name and  server name if you want and click Next


       4.   Select your JBoss location on your hard drive and jdk’s installation. Click        Finish.



JBoss is ready to run.

Deploy Application on Server
To deploy Spring MVC app on JBoss 7 we’ll use eclipse plugins support. It will automatically build, compile project and copy war file to jboss deployments folder.
       1.   Run JBoss


       2.   Using Drag and Drop put your app on server icon.


       3.   See logs

INFO  [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-3) FrameworkServlet 'appServlet': initialization completed in 657 ms
INFO  [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /springMVCtutorial
INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "springMVCtutorial.war"

Application is deployed

       4.   Go to web browser and go to http://localhost:8080/springMVCtutorial/

Import existing project
Generally you will be not creating new project using Eclipse / STS wizards. Probably you will import it from existing sources. To use eclipse deployment support imported maven project needs to be configured in STS. Environment has to know that this is a web module and can be deployed to server.

       1.   File -> Import…


       2.   Select Existing Maven Projects… and click Next


       3.   Set root directory and Finish



To make imported project be sure that project facets are selected like on the picture below. (project Properties -> Projects Facets)



poniedziałek, 1 kwietnia 2013

Utilizing System Properties with Jboss 6.x/7.x and Spring


JBoss gives us possibility to set our application properties / configuration as a java system property. It is very useful for configuring enterprise apps per environment. Usage of this feature is different between JBoss versions. I’ll show you how to utilize it on JBoss AS 6 and 7. Then you will see the most valuable thing, which is SystemPropertiesService from Spring Framework.

JBoss 6.x
Create xml file (deleult name is properties-service.xml ) like shown below and copy it to %JBOSS_HOME%/server/default/deploy/ folder
<server>
  <mbean code="org.jboss.varia.property.SystemPropertiesService" 
  name="jboss:type=Service,name=SystemProperties">
    <!-- 
       | Load properties from each of the given comma seperated URLs
    <attribute name="URLList">
      http://somehost/some-location.properties,
      ./conf/somelocal.properties
    </attribute>
    -->
    <attribute name="Properties">
      gkolpu.blog.example1=MY_Property1
      gkolpu.blog.example2=MY_Property2
    </attribute>
  </mbean>
</server>

JBoss 7.x
Add the code attached below to standalone.xml file, it should be added after <extensions> tag.

<system-properties>
<property name="gkolpu.blog.example1" value="MY_Property1"/>
<property name="gkolpu.blog.example2" value="MY_Property2"/>
</system-properties>
Spring Configuration
Add this code to your spring configuration. It will load your file and make your properties visible in the Spring context. There is one parameter to define, example below use SYSTEM_PROPERTIES_MODE_OVERRIDE which means that you can set all needed properties in the file embedded in your project but they will be override by the properties specified in JBoss configuration. You have 3 options here:
static int
SYSTEM_PROPERTIES_MODE_FALLBACK
          Check system properties if not resolvable in the specified properties.
static int
SYSTEM_PROPERTIES_MODE_NEVER
          Never check system properties.
static int
SYSTEM_PROPERTIES_MODE_OVERRIDE
          Check system properties first, before trying the specified properties.
<bean class="org.springframework.beans.factory.
                       config.PropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" 
                 value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="location" 
                 value="classpath:application.properties"/>
</bean>