JavaEtMoi Core :: javaetmoi-spring4-vfs2-support - jar

JBoss VFS 2 support for Spring Framework 4.0

License

License

GroupId

GroupId

com.javaetmoi.core
ArtifactId

ArtifactId

javaetmoi-spring4-vfs2-support
Last Version

Last Version

1.4.1
Release Date

Release Date

Type

Type

jar
Description

Description

JavaEtMoi Core :: javaetmoi-spring4-vfs2-support - jar
JBoss VFS 2 support for Spring Framework 4.0
Project URL

Project URL

https://github.com/arey/spring4-vfs2-support
Source Code Management

Source Code Management

https://github.com/arey/spring4-vfs2-support

Download javaetmoi-spring4-vfs2-support

How to add to project

<!-- https://jarcasting.com/artifacts/com.javaetmoi.core/javaetmoi-spring4-vfs2-support/ -->
<dependency>
    <groupId>com.javaetmoi.core</groupId>
    <artifactId>javaetmoi-spring4-vfs2-support</artifactId>
    <version>1.4.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.javaetmoi.core/javaetmoi-spring4-vfs2-support/
implementation 'com.javaetmoi.core:javaetmoi-spring4-vfs2-support:1.4.1'
// https://jarcasting.com/artifacts/com.javaetmoi.core/javaetmoi-spring4-vfs2-support/
implementation ("com.javaetmoi.core:javaetmoi-spring4-vfs2-support:1.4.1")
'com.javaetmoi.core:javaetmoi-spring4-vfs2-support:jar:1.4.1'
<dependency org="com.javaetmoi.core" name="javaetmoi-spring4-vfs2-support" rev="1.4.1">
  <artifact name="javaetmoi-spring4-vfs2-support" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.javaetmoi.core', module='javaetmoi-spring4-vfs2-support', version='1.4.1')
)
libraryDependencies += "com.javaetmoi.core" % "javaetmoi-spring4-vfs2-support" % "1.4.1"
[com.javaetmoi.core/javaetmoi-spring4-vfs2-support "1.4.1"]

Dependencies

compile (5)

Group / Artifact Type Version
org.springframework : spring-web jar 4.0.3.RELEASE
org.springframework : spring-orm Optional jar 4.0.3.RELEASE
org.springframework : spring-webmvc Optional jar 4.0.3.RELEASE
org.hibernate : hibernate-entitymanager Optional jar 4.3.8.Final
javax.servlet : servlet-api Optional jar 2.5

Project Modules

There are no modules declared in this project.

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

Version Release date Features
1.4.2-SNAPSHOT next version
1.4.1 05/03/2016 JBoss5GenericXmlApplicationContext added
1.4.0 20/03/2015 Add VFS2 support for Hibernate.
1.3.0 01/10/2014 Add VFS2 support for Spring MVC webjars.
1.2.0 02/07/2014 Fix added for Spring Framework 4.0.4 and 4.0.5. Add VFS2 support for JPA (Vfs2PersistenceUnitManager)
1.1.0 31/03/2014 JBoss5XmlWebApplicationContext added
1.0.0 29/03/2014 First release which supports Spring Framework 4.0.3

Build Status

Cloudbees Jenkins : Build Status

Versions

Version
1.4.1
1.4.0
1.3.0