JBoss VFS 2 support for Spring Framework 4.x
Java
Clone or download
Latest commit 202a192 Mar 5, 2016

readme.md

JBoss VFS 2 support for Spring Framework 4.0

Spring Framework 4.0 removed support for JBoss AS 5's VFS variant. The Spring 4 VfsUtils class does not support any more the VFS 2 of JBoss AS 5 and JBoss 5.x EAP. This project provides an AnnotationConfigWebApplicationContext subclass which support the VFS 2 of JBoss 5. The JBoss5AnnotationConfigWebApplicationContext and JBoss5XmlWebApplicationContext classes worked with the Vfs2Utils class that is a simple copy/paste of the VfsUtils class of the Spring Framework 3.2.

Quick Start

  1. Download the jar though Maven:
<dependency>
  <groupId>com.javaetmoi.core</groupId>
  <artifactId>javaetmoi-spring4-vfs2-support</artifactId>
  <version>1.4.1</version>
</dependency> 

The Spring Batch Toolkit artefacts are available from Maven Central

Maven Central

  1. For Spring Java Config, declare the JBoss5AnnotationConfigWebApplicationContext into the web.xml

Either with the Spring ContextLoaderListener:

<context-param>
  <param-name>contextClass</param-name>
  <param-value>com.javaetmoi.core.spring.JBoss5AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>com.example.MyAppWebConfig</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Or with the Spring DispatcherServlet:

<servlet>
  <servlet-name>mvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextClass</param-name>
    <param-value>com.javaetmoi.core.spring.JBoss5AnnotationConfigWebApplicationContext</param-value>
  </init-param>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.example.MyAppWebConfig</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
  1. For traditional XML configuration, declare the JBoss5XmlWebApplicationContext into the web.xml
<context-param>
  <param-name>contextClass</param-name>
  <param-value>com.javaetmoi.core.spring.JBoss5XmlWebApplicationContext</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
  1. Spring JPA support

This module provides the Vfs2PersistenceUnitManager class that extends the Vfs2PersistenceUnitManager from Spring ORM in order to use the Vfs2PathMatchingResourcePatternResolver. How to use it:

@Bean
public EntityManagerFactory entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPersistenceUnitName("myPersitenceUnit");
    em.setPersistenceUnitManager(persistenceUnitManager());
    // ...
    em.afterPropertiesSet();
    return em.getObject();
}

@Bean
public Vfs2PersistenceUnitManager persistenceUnitManager() {
    Vfs2PersistenceUnitManager pum = new Vfs2PersistenceUnitManager(applicationContext);
    pum.setDefaultDataSource(dataSource);
    pum.setDefaultPersistenceUnitName("myPersitenceUnit");
    pum.setPackagesToScan("com.javaetmoi.demo.domain.model");
    return pum;
} 

With Hibernate implementation, you have to disable the DefaultScanner by using the DisableHibernateScanner.

First, customize the hibernate.ejb.resource_scanner hibernate property:

<util:map id="hibernateAdditionalProperties">
   <entry key="hibernate.ejb.resource_scanner"value="com.javaetmoi.core.spring.vfs.DisableHibernateScanner"/>
 </util:map>

Then declare it into the entityManagerFactory:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">
   ...
   <property name="jpaPropertyMap" ref="hibernateAdditionalProperties"/>
 </bean>
  1. Spring MVC webjar support

With Spring MVC, static resources could be served from a webjar. The Vfs2ResourceHandlerRegistry class prevents you for having the error java.lang.ClassNotFoundException: org.jboss.vfs.VFS from BaseClassLoader.

How to use it:

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private ApplicationContext applicationContext;
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        new Vfs2ResourceHandlerRegistry(registry, applicationContext)
                .addResourceHandler("/resources/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}

References

Release Note

VersionRelease dateFeatures
1.4.2-SNAPSHOTnext version
1.4.105/03/2016JBoss5GenericXmlApplicationContext added
1.4.020/03/2015Add VFS2 support for Hibernate.
1.3.001/10/2014Add VFS2 support for Spring MVC webjars.
1.2.002/07/2014Fix added for Spring Framework 4.0.4 and 4.0.5. Add VFS2 support for JPA (Vfs2PersistenceUnitManager)
1.1.031/03/2014JBoss5XmlWebApplicationContext added
1.0.029/03/2014First release which supports Spring Framework 4.0.3

Build Status

Cloudbees Jenkins : Build Status