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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:22:09+00:00 2026-06-15T13:22:09+00:00

//Located in com\src\myproject\services package com.src.myproject.services; public interface IMyService { public boolean Method1(); } //Located

  • 0

//Located in com\src\myproject\services

package com.src.myproject.services;

public interface IMyService {
    public boolean Method1();

}

//Located in com\src\myproject\services

package com.src.myproject.services;

public class MyService implements IMyService {


    @Autowired
    private TestMapper testMapper;

    @Override
    public boolean Method1() {


        return gettestMapper().GetOrder(1); //Get null pointer exception as testMapper is null in debug mode
    }



    public TestMapper gettestMapper(){

            return testMapper;
        }


    public void settestMapper(TestMapper testMapper){
        this.testMapper=testMapper;
        }

}

My mapper.java files are located under com\src\mappers

and corresponding mapper.xml is located under src\main\resources\com\src\myproject\mappers

My servelet-context.xml file is

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
                    http://www.springframework.org/schema/tx 
                    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context-3.0.xsd
                    http://www.springframework.org/schema/util
                    http://www.springframework.org/schema/util/spring-util-3.1.xsd">


    <!-- Root Context: defines shared resources visible to all other web components -->

    <context:property-placeholder location="/WEB-INF/spring/jdbc.properties,/WEB-INF/spring/mybatis.properties" />

    <context:component-scan base-package="com.src.myproject.controllers" />
    <context:component-scan base-package="com.src.myproject.services" />


    <!-- Enable annotation style of managing transactions -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- Declare a datasource that has pooling capabilities -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close" p:driverClass="${app.jdbc.driverClassName}"
    p:jdbcUrl="${app.jdbc.url}" p:user="${app.jdbc.username}" p:password="${app.jdbc.password}"
    p:acquireIncrement="10" p:idleConnectionTestPeriod="60" p:maxPoolSize="100"
    p:maxStatements="50" p:minPoolSize="10" />

    <!-- Declare a transaction manager -->
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
    p:dataSource-ref="dataSource"
    autowire="byName" />


    <!-- define the SqlSessionFactory, notice that configLocation is not needed when you use MapperFactoryBean -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="${typeAliasesPackage}" />
    </bean>

    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.src.myproject.mappers" />
         <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    </bean> 
</beans>

The autowiring in the services files is always null and gives null ref exception when I try to use any method from the mapper files via auto wire.

  • 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-15T13:22:13+00:00Added an answer on June 15, 2026 at 1:22 pm

    You should never instantiate Spring beans directly. It’s the container that is responsible for object creation. Thus in your controller, instead of:

    IMyService mySvc = new Service();
    

    Create such field:

    @Autowired
    private IMyService mySvc;
    

    Spring will discover it and assign proper value, which is an instance of MyService creates beforehand for you.

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

Sidebar

Related Questions

I've a java program as shown below: package com.abc.myproject; import java.util.*; class test {
Under WEB-INF/classes folder i have java class files structured in package hierarchy(e.g: com.company.app )
When users go to foo.com/bar they should see the site located in foo.com/bar/public. The
My program is located at http://server2.abcd.com/myprogram/ . Our webmaster has set up a subdomain:
Problem is located on http://www.preownedweddingdresses.com/ We have a dresses slider at the bottom, select
The XML feed is located at: http://xml.betclick.com/odds_fr.xml I need a php loop to echo
I have a site located at http://www.mySite.com . My html/PHP pages are located at
I have a Joomla Website located at http://www.MikeSilvis.com , and upon going to the
Suppose I have a page located at www.example.com/foo , and it contains an <iframe>
I have some pdf files located on a http server: Like: http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf http://domain.com/files/file1.pdf

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.