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 3316602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:29:19+00:00 2026-05-17T22:29:19+00:00

I’ve just read about @Resource annotation from this article ( http://www.infoq.com/articles/spring-2.5-part-1 ) and wish

  • 0

I’ve just read about @Resource annotation from this article (http://www.infoq.com/articles/spring-2.5-part-1) and wish to use it on Tomcat 6.0.26 and Spring 3.0.3

But it does not work — field ds in Users class does not initialized and I’ve got NullPointerException when I try to made a query.

File src/org/example/db/Users.java

package org.example.db;
import javax.sql.DataSource;
import javax.annotation.Resource;

@Repository
public class Users {

 @Resource private DataSource ds;
 ...
}

File WEB-INF/spring-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:jee="http://www.springframework.org/schema/jee"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/jee
 http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd">

 <context:component-scan base-package="org.example.web.controller,org.example.db" />

 <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
  <property name="alwaysUseJndiLookup" value="true" />
 </bean>

 <jee:jndi-lookup id="ds" jndi-name="java:comp/env/jdbc/mydb" />

</beans>

File WEB-INF/web.xml

 <resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/mydb</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>

In log file:

DEBUG 2010-09-27 21:56:00,085: Creating shared instance of singleton bean 'ds'
DEBUG 2010-09-27 21:56:00,085: Creating instance of bean 'ds'
DEBUG 2010-09-27 21:56:00,086: Eagerly caching bean 'ds' to allow for resolving potential circular references
DEBUG 2010-09-27 21:56:00,106: Invoking afterPropertiesSet() on bean with name 'ds'
DEBUG 2010-09-27 21:56:00,116: Finished creating instance of bean 'ds'
DEBUG 2010-09-27 21:56:00,149: Found injected element on class [org.example.db.Users]: ResourceElement for private javax.sql.DataSource org.example.db.Users.ds
DEBUG 2010-09-27 21:56:00,152: Found injected element on class [org.example.db.Users]: ResourceElement for private javax.sql.DataSource org.example.db.Users.ds
DEBUG 2010-09-27 21:56:00,161: Processing injected method of bean 'users': ResourceElement for private javax.sql.DataSource org.example.db.Users.ds
DEBUG 2010-09-27 21:56:00,163: Returning cached instance of singleton bean 'ds'
DEBUG 2010-09-27 21:56:00,442: Returning cached instance of singleton bean 'ds'
DEBUG 2010-09-27 21:56:00,593: Rejected bean name 'ds': no URL paths identified
DEBUG 2010-09-27 21:56:00,738: Rejected bean name 'ds': no URL paths identified

I don’t know why it does not work. I found in documentation this:

NOTE: A default CommonAnnotationBeanPostProcessor will be registered by the “context:annotation-config” and “context:component-scan” XML tags. Remove or turn off the default annotation configuration there if you intend to specify a custom CommonAnnotationBeanPostProcessor bean definition!

I think it may be about my problem, but in this case I don’t know how to “Remove or turn off the default annotation configuration”.

Please help.
Thanks in advance!

  • 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-05-17T22:29:21+00:00Added an answer on May 17, 2026 at 10:29 pm

    For now this issue is resolved.

    All this code works, but I think the problem was in some of the related classes. For example, I have following autowiring hierarchy: dataSource injects to Users class, Users class injects to Validator, Validator is called from Controller. In this chain were a few bugs:

    • Users are created using a new Validator instance
    • after @Autowiring propagation, User did not inject to Validator because this class was in another package and component-scan not find it
    • later User did not inject to Validator because this class does not have @Component annotation
    • Controller creates new instance of Validator using the default constructor

    After I resolve all these issues all works fine.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.