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

  • Home
  • SEARCH
  • 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 8807663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:25:24+00:00 2026-06-14T02:25:24+00:00

I have used beans:profiles in my xml like this: <beans profile=dev> <bean id=dataSource destroy-method=close

  • 0

I have used beans:profiles in my xml like this:

    <beans profile="dev">
        <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.internal.url}" />
            <property name="username" value="${jdbc.internal.username}" />
        </bean>
   </beans>

I’ve set the spring.active.profiles in web.xml:

<servlet>
    <servlet-name>myapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/myapp-servlet.xml</param-value>
    </init-param>
    <init-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>dev</param-value>
    </init-param>
</servlet>

My code structure is like this:

//controller
@Controller 
public class MyController {
  @Autowired
  private MyService myService;
  ....
}

//service implementation
@Service("myservice")
public class MyServiceImpl implements MyService {
  @Autowired
  DBService dbService;
} 

//db service
@Service("dbservice)
public class DBServiceImpl implements DbService {
  @Autowired
  public void setDataSource (Datasource ds) { 
    this.jdbcTemplate = new JdbcTemplate(ds);
  }
}

Error:

Error creating bean with name ‘myController’: Injection of
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private MyService
MyController.myService;
nested exception is
org.springframework.beans.factory.BeanCreationException:

nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘dbService’: Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire method: public void
DBServiceImpl.setDataSource(javax.sql.DataSource); nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
matching bean of type [javax.sql.DataSource] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for
this dependency. Dependency annotations: {} at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)

  • 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-14T02:25:25+00:00Added an answer on June 14, 2026 at 2:25 am

    My guess it that you are using profile in DispatcherServlet context, while DataSource is likely located in the root application context.

    See Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

    update: try using context-params (taken from here):

    <context-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>dev</param-value>
    </context-param>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used to have the following bean defined in XML (it worked!): <bean id=session
I have created a spring bean that contains a list of other beans, like
I have used this website for testing http://www.webpagetest.org and among some suggestions for optimization
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
We have faces-config.xml in JSF 1.0 where we entry about managed-beans, dependencies & navigations
Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
I have two beans of the same name and same class. I want to
I have used this statements to populate jcombobox from MySql database table using Hibernate
In my application I have beans annotated with @Profile(prod) and @Profile(demo) . The first
I used to have all my DAOs extend the JdoDaoSupport class which is now

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.