JBoss VFS 2 support for Spring Framework 4.x
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.
<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
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>
<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>
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>
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/");
}
}
Cloudbees Jenkins :