java.lang.NullPointerException exception handling

created at 08-04-2021 views: 38

exception

java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at cn.itcast.util.JDBCUtils.<clinit>(JDBCUtils.java:24)
    at cn.itcast.dao.UserDao.<init>(UserDao.java:18)
    at cn.itcast.test.UserDaoTest.testLogin(UserDaoTest.java:17)
    at cn.itcast.test.UserDaoTest.main(UserDaoTest.java:10)
Exception in thread "main" java.lang.IllegalArgumentException: Property 'dataSource' is required
    at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:152)
    at org.springframework.jdbc.core.JdbcTemplate.<init>(JdbcTemplate.java:166)
    at cn.itcast.dao.UserDao.<init>(UserDao.java:18)
    at cn.itcast.test.UserDaoTest.testLogin(UserDaoTest.java:17)
    at cn.itcast.test.UserDaoTest.main(UserDaoTest.java:10)

Analysis

As shown in the figure, the essence is that the druid.properties file is not found

Solution

Put the druid.properties file into resources (the package is marked as the resource path)

druid.properties

created at:08-04-2021
edited at: 08-04-2021: