Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:00:45+00:00 2026-06-10T17:00:45+00:00

This may be trivial, but I seem to continuously run at a wall and

  • 0

This may be trivial, but I seem to continuously run at a wall and can’t find my mistake.

I am extending the Apache James 3 mailserver which used Spring and OpenJPA. I would now like to access a Service class which used a JPA Repository via JMX.

The Service is

@Component
@ManagedResource(objectName = "bean:name=BlacklistServiceImpl", description = "The service providing access to the blacklisted recipients in the DB.")
public class BlacklistServiceImpl implements BlacklistService {

    @Autowired
    private BlackListRepository blackListRepository;
    @Autowired
    private ConversationService conversationService;

    @Override
    @ManagedOperation(description = "Add address to blacklist")
    @ManagedOperationParameter(name = "address", description = "Address to add to blacklist.")
    public void addAddress(String address) {
        //Stuff
    }

    @Override
    @ManagedOperation(description = "Remove address from blacklist")
    @ManagedOperationParameter(name = "address", description = "Address to remove from blacklist.")
    public void removeAddress(String address) {
        //Stuff
    }
}

and I have added to following to my context:

<bean id="mailserverBeansExporter" class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
    <property name="beans">
        <map>
            <entry key="bean:name=BlacklistServiceImpl">
                <bean class="<snip>.services.blacklist.impl.BlacklistServiceImpl"/>
            </entry>
        </map>
    </property>
</bean>

While I have managed to build this, James crashes at startup with the following exception:

    [INFO] Starting Apache James Server...
    [INFO] ------------------------------------------------------------------------
    [ERROR] FATAL ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Error creating bean with name 'blacklistServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.B
    eanCreationException: Could not autowire field: private <snip>.core.repositories.blacklist.BlackListRepository <snip>.service
    s.blacklist.impl.BlacklistServiceImpl.blackListRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean
     of type [<snip>.repositories.blacklist.BlackListRepository] found for dependency: expected at least 1 bean which qualifies as autowire cand
    idate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    [INFO] ------------------------------------------------------------------------
    [INFO] Trace
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blacklistServiceImpl': Injection of autowired dependencies failed; neste
    d exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private <snip>.repositories.blacklist.Blac
    kListRepository <snip>.services.blacklist.impl.BlacklistServiceImpl.blackListRepository; nested exception is org.springframework.beans.facto
    ry.NoSuchBeanDefinitionException: No matching bean of type [<snip>.repositories.blacklist.BlackListRepository] found for dependency: expecte
    d at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(re
    quired=true)}
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java
    :285)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
            at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
            at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
            at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
            at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
            at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private <snip>.repositories.blacklist.BlackLis
    tRepository <snip>.services.blacklist.impl.BlacklistServiceImpl.blackListRepository; nested exception is org.springframework.beans.factory.N
    oSuchBeanDefinitionException: No matching bean of type [<snip>.repositories.blacklist.BlackListRepository] found for dependency: expected at
     least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(requir
    ed=true)}
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.j
    ava:502)
            at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java
    :282)
            ... 33 more
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [<snip>.repositories.blacklist.BlackLis
    tRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframe
    work.beans.factory.annotation.Autowired(required=true)}
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.j
    ava:474)
            ... 35 more

The BlackListRepository has two implementations: the JPABlackListRepository and the InMemoryBlackListRepository, which is used for unit testing. I tried to solve the problem by adding

<bean id="BlackListRepository" class="<snip>.JPABlackListRepository" />

to the common-context, but this lead to the unit tests failing as now the in memory implementation wasn’t used anymore.

I would appreciate any help.

Update:

While debugging (and thanks to the comment below) I realized that only removing BOTH the @Component and @Managed* annotations as well as the section

<bean id="mailserverBeansExporter" class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
    <property name="beans">
        <map>
            <entry key="bean:name=BlacklistServiceImpl">
                <bean class="at.willhaben.safe.sms.core.services.blacklist.impl.BlacklistServiceImpl"/>
            </entry>
        </map>
    </property>
</bean>

leads to a clean startup. Obviously then JMX doesn’t work, but leaving any of those statements in the code leads to above exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:00:47+00:00Added an answer on June 10, 2026 at 5:00 pm

    Like the other comments have noted, the exception is not really related to JMX then – the issue seems to be that a dependency is not being found.

    You have mentioned that when you explicitly pass in a repository this way:

    <bean id="BlackListRepository" class="<snip>.JPABlackListRepository" />

    then it works, if that is the case, you can selectively override it for tests alone, create a test application context:

    test-applicationcontext.xml

     <import resource="prod-context.xml"/>
     <bean id="BlackListRepository" class="..InMemoryBlackListRepository"/>
    

    This will ensure that InMemoryBlackLIstRespository is the one injected.

    Also to expose your service bean over Jmx:

    <bean name="blacklistService" class="..BlackListServiceImpl"/>
    
    <bean id="mailserverBeansExporter" class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
    <property name="beans">
        <map>
            <entry key="bean:name=BlacklistServiceImpl" value-ref="blacklistService">
    
            </entry>
        </map>
    </property>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem trivial, but I can't figure it out how to 1) retrieve
this may seem trivial but i can't figure out why DNN reports this error,
This may be something common and trivial, but I seem to be having trouble
This question may seem trivial, but I hope you won't ignore it. Before destroying
This may seem a trivial question, but it's one that's bothered me a lot
This may be a simple question but I can;t find the answer anywhere. Here
This may seem trivial for most people but I am getting problems in determining
It may seem a trivial question, but I've searched a lot and couldn't find
This may seem trivial but I have no idea how and the lack of
Okay, this may be trivial, but I'm hoping somebody can give me a straightforward

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.