Coder Social home page Coder Social logo

Comments (4)

snicoll avatar snicoll commented on August 24, 2024 1

@1haann much better, thanks.

@Configuration
public class TestConfig {
  @Bean
  public TestDao testDao(){
    return new TestDaoImpl();
  }
}

From the original description, I've extracted this. Please review the best practices. Native processing takes decision at build-time. You are exposing a bean of type TestDao so no handling of autowired fields for TestDaoImpl will happen as the type is not exposed. Try rewriting it as follows:

@Configuration
public class TestConfig {
  @Bean
  public TestDaoImpl testDao(){
    return new TestDaoImpl();
  }
}

For further support, please ask on StackOverflow as this issue tracker is meant for bug reports and enhancements only.

from spring-boot.

snicoll avatar snicoll commented on August 24, 2024

@liufangzhou53 please take the time to format the report correctly. Right now it's a dump of various elements that are very hard to read. You can edit your original description. If you need help with formatting, there is https://docs.github.com/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax.

from spring-boot.

1haann avatar 1haann commented on August 24, 2024

Hello. First of all, I am not good at English, so please understand. I saw the code and error message of your writing.

@slf4j
public class TestDaoImpl implements TestDao {

    @Autowired
    private DbTools dbTools;

    @Autowired
    private TestMapper testMapper;

    String tableName ="testtable";

    public TestDaoImpl() {
    }
// public TestDaoImpl(){
// super.setTableName(tableName);
// }

    @Override
    public List<Map> getName2(String mkt) {
// DbTools dbTools = new DbTools();
        String a = dbTools.FilterDatesrc("getname");
        log.info("dbTools=====>"+a);
        if ("Y".equals(GlobalInfo.centrally)) {
            MultipleDataSource.setDataSourceKey(dbTools.FilterDatesrc("getname", mkt));
        } else {
            MultipleDataSource.setDataSourceKey(dbTools.FilterDatesrc("getname"));
        }
        List list = testMapper.getName2();
        return list;
    }

    @Override
    public List<TestDto> getName(String mkt) {
        return null;
    }
}

"java.lang.NullPointerException: null at com.efuture.business.dao.Impl.TestDaoImpl.getName2(TestDaoImpl.java:41)"

This error message seems to be a problem caused by the testDaoImpl class not being registered as bean.
TestDaoImpl class is not registered as bean DI doesn't seem to work successfully for dbTools and testMapper.
I think you should register as Bean through components like @component, @service in TestDaoImpl class.
This is my first comment on someone else's code and I hope the issue is fixed.

from spring-boot.

liufangzhou53 avatar liufangzhou53 commented on August 24, 2024

thanks

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.