严重: Servlet.service() for servlet [springmvc] in context with path [/fourth] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.ssm.fourth.service.MapServiceImpl.selectAll(MapServiceImpl.java:20)
at com.ssm.fourth.controller.MapController.second(MapController.java:23)
下面是具体配置 和代码 跪求解决方法 谢谢了
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
springmvc
*.action
org.springframework.web.context.ContextLoaderListener
applicationContext.xml
<context:component-scan
base-package="com.ssm.fourth.service,com.ssm.fourth.dao"></context:component-scan>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<!-- 初始化连接池大小 -->
<property name="initialSize" value="${initialSize}"></property>
<!-- 连接池的最大数量 -->
<property name="maxActive" value="${maxActive}"></property>
<!-- 连接池的最大空闲 -->
<property name="maxIdle" value="${maxIdle}"></property>
<!-- 连接池的最小空闲 -->
<property name="minIdle" value="${minIdle}"></property>
<!-- 连接池的最大等待时间 -->
<!-- <property name="maxWaite" value="${maxWaite}"></property> -->
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybaties/SqlMapConfig.xml"/>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
springmvc.xml
<mvc:annotation-driven/>
<context:component-scan base-package="com.ssm.fourth.controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"/>
<property name="suffix" value=".jsp"/>
</bean>
代码:
package com.ssm.fourth.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ssm.fourth.entity.Map;
import com.ssm.fourth.service.MapService;
@Controller
@RequestMapping(value="b")
public class MapController {
@Autowired
private MapService mapService;
@RequestMapping(value="second.action")
public String second(){
System.out.println("second");
List<Map> list = mapService.selectAll();
for(int i=0;i < list.size();i++){
System.out.println(list.get(i).getLatitude());
}
return "second";
}
}
package com.ssm.fourth.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.ssm.fourth.entity.Map;
@Repository
public interface MapDao {
public List<Map> selectAll();
}
package com.ssm.fourth.service;
import java.util.List;
import com.ssm.fourth.entity.Map;
public interface MapService {
public List<Map> selectAll();
}
package com.ssm.fourth.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.ssm.fourth.dao.MapDao;
import com.ssm.fourth.entity.Map;
@Service
public class MapServiceImpl implements MapService{
@Qualifier("mapDao")
private MapDao mapDao;
@Override
public List<Map> selectAll() {
return this.mapDao.selectAll();
}
}