<bean id="MyDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg value="MyDataSource"/>
</bean>
Error creating bean with name 'template' defined in class path resource [application-context.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
I am not sure what I am doing wrong here to get above error? Have all of it defined in properties file correctly with correct variable name. what are the things to check for ?
There could be numerous reasons why Spring could not able to create a bean with name X, but clue always lies on the detailed stack trace. This error always has some underlying cause e.g. a ClassNotFoundException or a NoClassDefFoundError, which potentially signal a missing JAR file in the classpath.
The bean identifiers (id and name) Every bean has one or more ids (also called identifiers, or names; these terms refer to the same thing). These ids must be unique within the BeanFactory or ApplicationContext the bean is hosted in.
By far, the most common cause of the BeanCreationException is Spring trying to inject a bean that doesn't exist in the context. To diagnose this type of issue, we'll first make sure the bean is declared: either in an XML configuration file using the <bean /> element.
Beans are java objects that are configured at run-time by Spring IoC Container. BeanFactory represents a basic IoC container which is a parent interface of ApplicationContext. BeanFactory uses Beans and their dependencies metadata to create and configure them at run-time.
change
<bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg value="MyDataSource"/>
</bean>
to
<bean id="template" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="MyDataSource"/>
</bean>
because you don't want to inject String
value you want to inject referred bean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With