DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Classpath Scan Breaks When Migrating From JBoss4 to JBoss5

Spring Classpath Scan Breaks When Migrating From JBoss4 to JBoss5

Vineet Manohar user avatar by
Vineet Manohar
·
Apr. 09, 10 · Interview
Like (0)
Save
Tweet
Share
6.51K Views

Join the DZone community and get the full member experience.

Join For Free

Spring 2.5 classpath scan does not work on JBoss5 due to internal architecture changes in JBoss5. You may face this issue when migrating from JBoss4 to JBoss5. This article walks you through a simple fix, with code snippets.

Classpath scan issue

In JBoss 4, your application was probably using Spring 2.5.6 with classpath scan to load spring beans (as shown below). When migrating your code to JBoss5, you will notice that component-scan does not work with JBoss5. Symptoms may include null Spring components or if you were using Spring Seam integration and the Spring beans were loaded through classpath scan then you may be the following error:

Seam Code

public class LoginController extends Controller {
@In("#{userService}")
protected demo.entity.service.UserService userService;
public class LoginController extends Controller {
    @In("#{userService}")
    protected demo.entity.service.UserService userService;

Stacktrace

Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: loginController.#{userService}
at org.jboss.seam.Component.getValueToInject(Component.java:2335)
at org.jboss.seam.Component.injectAttributes(Component.java:1736)
at org.jboss.seam.Component.inject(Component.java:1554)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: loginController.#{userService}
 at org.jboss.seam.Component.getValueToInject(Component.java:2335)
 at org.jboss.seam.Component.injectAttributes(Component.java:1736)
 at org.jboss.seam.Component.inject(Component.java:1554)
 at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

Spring 2.5.6 dependency in pom.xml

 <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring</artifactId>
 <version>2.5.6</version>
 </dependency

Old spring config XML

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-init-method="init" default-destroy-method="shutdown">
<context:annotation-config />
<context:component-scan base-package="demo.dao.jpa" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/context

 http://www.springframework.org/schema/context/spring-context-2.5.xsd"
 default-init-method="init" default-destroy-method="shutdown">
 <context:annotation-config />
 <context:component-scan base-package="demo.dao.jpa" />
</beans>

If you run the above code in JBoss5, component-scan does not work. See this JIRA issue on Spring’s website.

Solution

You need to migrate your spring version from 2.5.6 to 3.0.0.RELEASE. Remove your old spring dependency for 2.5.6 and add the following. Add snippets for the components that your application needs. Here’s a list of common spring components and their maven dependencies.

New dependency

 <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
 <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.0.0.RELEASE</version>
<scope>test</scope>
</dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-test</artifactId>
 <version>3.0.0.RELEASE</version>
 <scope>test</scope>
 </dependency>

Complete list is available here. After making this change, build your project with the new dependencies. Your old code should work with Spring 3 on JBoss 5.1.0.GA.

From http://www.vineetmanohar.com/2010/04/08/spring-classpath-scan-issue-jboss5

Spring Framework Classpath (Java)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Integrate AWS Secrets Manager in Spring Boot Application
  • Best Navicat Alternative for Windows
  • 19 Most Common OpenSSL Commands for 2023
  • How To Set Up and Run Cypress Test Cases in CI/CD TeamCity

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: