Donate Share

One-JAR(TM)

Tracker: Bugs

5 Spring fails to find @Component bean with classpath scanning - ID: 2796172
Last Update: Comment added ( sslavic )

Originally reported by ulrik.sandberg, Apr 17, 2009, against the
onejar-maven-plugin.
I believe the problem is in One-JAR's classloading.

Original (and properly formatted) bug reports regarding this are here:
http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/#
comment-3788
http://code.google.com/p/onejar-maven-plugin/issues/detail?id=12

Best regards,
Hugo Josefson

---------------------------------------------------------------------------
-

What version of the product are you using? On what operating system?

onejar-maven-plugin 1.4.0, Windows XP

What steps will reproduce the problem?

Using onejar-maven-plugin in an annotation-based Spring project.
Chances are that it’s the classpath scanning that is the problem.

I had the following setup:

Class:

package com.example;

@Component("transformer")
public class MyTransformer {

Spring config:

<context:component-scan base-package="com.example" />

Bootstrapping code:

public static void main(String[] args) {
ApplicationContext context = new
ClassPathXmlApplicationContext("applicationContext.xml");
MyTransformer transformer = (MyTransformer)
context.getBean("transformer");
transformer.run();
}

I got the following exception:

NoSuchBeanDefinitionException: No bean named 'transformer' is defined

I then switched to this config, still using annotation-based
dependency
autowire, but requiring an explicit bean definition:

Spring config:

<context:annotation-config />
<bean id="transformer" class="com.example.MyTransformer" />



Hugo Josefson ( hugojosefson ) - 2009-05-24 19:58

5

Open

None

Nobody/Anonymous

Classloading

None

Public


Comments ( 2 )




Date: 2009-10-22 12:47
Sender: sslavic

Problem is in JarClassLoader, it's "protected void loadByteCode(InputStream
is, String jar, String tmp, Manifest man) throws IOException" method ignore
directories, which Spring's component scan tries to find via call to
"public Enumeration findResources(String name) throws IOException".


Date: 2009-09-08 14:08
Sender: sslavic

+1


Log in to comment.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.