@Component not being autowired

522 views
Skip to first unread message

Connick

unread,
Jan 6, 2012, 12:15:28 PM1/6/12
to ne...@googlegroups.com
I've got a bean (outlined below) which is marked as a @Component but is not being autowired at runtime. messageSource is always null ...the only difference between this and other classes (I can think of) is that it's being pulled from the repository. I must be missing something obvious?

@NodeEntity
@Configurable
@Component
public class Category 
{
    @Autowired
    private MessageSource messageSource;

    @GraphId
    Long id;

    @Fetch
    @JsonManagedReference
    @RelatedTo( type = "SUBCATEGORY", direction = Direction.OUTGOING )
    Set<Category> subcategories = new HashSet<Category>();

    @Indexed
    private String name;
    private String description;

    public Category() {
    }
    
    public Category( String name, String description ) {
        this.name = name;
        this.description = description;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        try {
            return messageSource.getMessage(name, null, name, LocaleContextHolder.getLocale());
        } catch (NullPointerException npe) {
            return name;
        }
    }
    ...
}

Michael Hunger

unread,
Jan 6, 2012, 12:33:48 PM1/6/12
to ne...@googlegroups.com
Do you have aspectj (spring-aspects) enabled in your project (needed for @Configurable)

Connick

unread,
Jan 6, 2012, 12:41:42 PM1/6/12
to ne...@googlegroups.com
I have the following ...

<context:annotation-config />
<context:spring-configured />

Connick

unread,
Jan 6, 2012, 12:51:37 PM1/6/12
to ne...@googlegroups.com
Hhmmm ...I don't think I've got the aspect maven plugin rigged properly.

Connick

unread,
Jan 6, 2012, 1:37:24 PM1/6/12
to ne...@googlegroups.com
Unfortunately that doesn't seem to be the problem. :/
          
           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <outxml>true</outxml>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                        <aspectLibrary>
                            <groupId>org.springframework.data</groupId>
                            <artifactId>spring-data-neo4j</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>${org.aspectj-version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${org.aspectj-version}</version>
                    </dependency>
                </dependencies>
            </plugin>

Connick

unread,
Jan 6, 2012, 4:36:21 PM1/6/12
to ne...@googlegroups.com
Still digging into this ...does this strike you as a spring-related or spring + neo related issue? Just want to be sure I'm not going off topic on this list. (all other wiring i.e. @Controller, @Service etc is working fine)

Stace 

Michael Hunger

unread,
Jan 6, 2012, 5:01:01 PM1/6/12
to ne...@googlegroups.com
If you use just the simple mapping you don't need to have spring-data-neo4j-aspects.

Could you try to leave off @Component?

Is the MessageSource autowired in other beans w/o issues?

Where do you retrieve instances of the Category class?

You might want to share you project to have me look into it.

Cheers

Michael

Connick

unread,
Jan 6, 2012, 5:13:27 PM1/6/12
to ne...@googlegroups.com
Unfortunately it's not something I can make public but I'll do my best to give you the pertinent details!

- Yes, message source is autowired elsewhere without issue. (inside @Service)
- Category instances are coming from a graph repository

I don't believe leaving @Component will have an effect seeing as it wasn't there initially but I will try anyhow when I'm back at my desk.

Silly question but what do you mean by "simple mapping" vs aspects? I understand the notion of aspects themselves but perhaps there's some configuration that I'm missing in order for simple mapping to work?

Stace

Michael Hunger

unread,
Jan 6, 2012, 5:53:40 PM1/6/12
to ne...@googlegroups.com
Then I'll try to test your approach on the hello-world example.

Spring Data Neo4j comes with 2 mapping modes, one is the simple  mapping that you used, which doesn't use aspects but copies the data out of the graph into your domain objects.

Advanced mapping uses aspectj to put a backing node or relationship behind your objects and does write and read-through to the node when you access or modify any field. 


Cheers

Michael
Reply all
Reply to author
Forward
0 new messages