Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.IllegalArgumentException:Property';数据源';是否需要Spring JDBC_Spring_Spring Mvc_Datasource_Spring Jdbc_Jdbctemplate - Fatal编程技术网

java.lang.IllegalArgumentException:Property';数据源';是否需要Spring JDBC

java.lang.IllegalArgumentException:Property';数据源';是否需要Spring JDBC,spring,spring-mvc,datasource,spring-jdbc,jdbctemplate,Spring,Spring Mvc,Datasource,Spring Jdbc,Jdbctemplate,我不确定我做错了什么,我试图使用jdbc调用执行一个存储过程,但每当我执行它的异常时 java.lang.IllegalArgumentException:属性“dataSource”是必需的 控制器类: @Controller public class GpsController { @RequestMapping(value="h",method=RequestMethod.POST) public void show(@ModelA

我不确定我做错了什么,我试图使用jdbc调用执行一个存储过程,但每当我执行它的异常时 java.lang.IllegalArgumentException:属性“dataSource”是必需的

控制器类:

    @Controller
    public class GpsController {

        @RequestMapping(value="h",method=RequestMethod.POST)    
        public void show(@ModelAttribute("PredefinedPath") PredefinedPath predefinedPath)

        { 

            PredefinedPathService service=new PredefinedPathService();
            //passing dto obj to service
             boolean res=   service.savePredefinedPath(predefinedPath);
        }
DTO类别:

    //Entity Class Getters and setters
    public class PredefinedPath {

        public int getPredefinedPath_Id() {
            return PredefinedPath_Id;
        }
        public void setPredefinedPath_Id(int predefinedPath_Id) {
            PredefinedPath_Id = predefinedPath_Id;
        }
        public String getPredefinedPath_Name() {
            return PredefinedPath_Name;
        }
        public void setPredefinedPath_Name(String predefinedPath_Name) {
            PredefinedPath_Name = predefinedPath_Name;
        }
        public String getSource() {
            return Source;
        }
        public void setSource(String source) {
            Source = source;
        }
        public String getDestination() {
            return Destination;
        }
        public void setDestination(String destination) {
            Destination = destination;
        }
        public String getEstimate_km() {
            return Estimate_km;
        }
        public void setEstimate_km(String estimate_km) {
            Estimate_km = estimate_km;
        }
        public double getSource_Latitude() {
            return Source_Latitude;
        }
        public void setSource_Latitude(double source_Latitude) {
            Source_Latitude = source_Latitude;
        }
        public double getSource_Longtitude() {
            return Source_Longtitude;
        }
        public void setSource_Longtitude(double source_Longtitude) {
            Source_Longtitude = source_Longtitude;
        }
        public double getDestination_Latitude() {
            return Destination_Latitude;
        }
        public void setDestination_Latitude(double destination_Latitude) {
            Destination_Latitude = destination_Latitude;
        }
        public double getDestination_Longtitude() {
            return Destination_Longtitude;
        }
        public void setDestination_Longtitude(double destination_Longtitude) {
            Destination_Longtitude = destination_Longtitude;
        }
        public String getEffectiveFromDate() {
            return EffectiveFromDate;
        }
        public void setEffectiveFromDate(String effectiveFromDate) {
            EffectiveFromDate = effectiveFromDate;
        }
        public String getEffectiveToDate() {
            return EffectiveToDate;
        }
        public void setEffectiveToDate(String effectiveToDate) {
            EffectiveToDate = effectiveToDate;
        }
        public int getStatus_Id() {
            return Status_Id;
        }
        public void setStatus_Id(int status_Id) {
            Status_Id = status_Id;
        }
        private int PredefinedPath_Id;
        private String PredefinedPath_Name;
        private String Source;
        private String Destination;
        private String Estimate_km;
        private double Source_Latitude;
        private double Source_Longtitude;
        private double Destination_Latitude;
        private double Destination_Longtitude;
        private String EffectiveFromDate;
        private String EffectiveToDate;
        private int Status_Id;


    }
DAO类:

        import javax.sql.DataSource;

        import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
        import org.springframework.jdbc.core.namedparam.SqlParameterSource;
        import org.springframework.jdbc.core.simple.SimpleJdbcCall;
        import com.Ss.App.dto.PredefinedPath;

        public class PredefinedPathDaoImpl {

             private DataSource dataSource;
               private SimpleJdbcCall jdbcCall;

               public void setDataSource(DataSource dataSource) {
                  this.dataSource = dataSource;

               }


          public boolean savePredefined(PredefinedPath predefinedPathDto)
            { 


                    System.out.println("INSIDE DAO");
                    this.jdbcCall =  new SimpleJdbcCall(dataSource).withProcedureName("PredefinedPath_Insert");
                    SqlParameterSource sqlParameterSource = new MapSqlParameterSource()
                    .addValue("PredefinedPath_Name", predefinedPathDto.getPredefinedPath_Name())
                    .addValue("Source", predefinedPathDto.getSource())
                    .addValue("Destination", predefinedPathDto.getDestination())
                    .addValue("Source_Latitude", predefinedPathDto.getSource_Latitude())
                    .addValue("Source_Longtitude", predefinedPathDto.getSource_Longtitude())
                    .addValue("Destination_Latitude", predefinedPathDto.getDestination_Latitude())
                    .addValue("Destination_Longtitude", predefinedPathDto.getDestination_Longtitude())
                    .addValue("EffectiveFromDate",null)
                    .addValue("EffectiveToDate",null)
                    .addValue("Status_Id", 4);
                    jdbcCall.execute(sqlParameterSource);






                return true;
            }
        }  
服务类别:

    import com.Ss.App.dto.PredefinedPath;

    import com.Ss.App.model.dao.PredefinedPathDaoImpl;

    public class PredefinedPathService {

         PredefinedPathDaoImpl predefinedPathDao=new PredefinedPathDaoImpl();
         public boolean savePredefinedPath(PredefinedPath predefinedPathdto)
         {

            boolean result=predefinedPathDao.savePredefined(predefinedPathdto);

            return result;


         }
    }
弹簧配置:

    <?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:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <context:component-scan base-package="com.Ss.App"></context:component-scan> 

            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/view/"/>
            <property name="suffix" value=".jsp"/>

            </bean>
             <!-- Definition for studentJDBCTemplate bean -->
       <bean id="PredefinedPathDaoImpl"  class="com.Ss.App.model.dao.PredefinedPathDaoImpl">
          <property name="DataSource"  ref="dataSource" />    
       </bean>
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"  value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
            <property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=test"></property>
            <property name="username" value="sa"></property>
            <property name="password" value="pass"></property>
        </bean>




    <mvc:annotation-driven />



            </beans>   

web.config

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
      <display-name>SpringAngularjs</display-name>
      <welcome-file-list>
        <welcome-file>page.jsp</welcome-file>

      </welcome-file-list>
      <servlet>
      <servlet-name>spring</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      </servlet>

      <servlet-mapping>
      <servlet-name>spring</servlet-name>
      <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>       

斯普林安格拉斯
page.jsp
春天
org.springframework.web.servlet.DispatcherServlet
春天
/

您自己实例化控制器中的服务时,它不是由Spring管理的

这就是为什么这个bean中没有设置数据源

替换:

@Controller
public class GpsController {

        @RequestMapping(value="h",method=RequestMethod.POST)    
        public void show(@ModelAttribute("PredefinedPath") PredefinedPath predefinedPath)
        { 

            PredefinedPathService service=new PredefinedPathService();
            //passing dto obj to service
             boolean res = service.savePredefinedPath(predefinedPath);
        }
}


请添加stacktrace这里是stacktrace:谢谢,现在已经修好了。
@Controller
public class GpsController {
   @Autowired
   private PredefinedPathService service;

   @RequestMapping(value="h",method=RequestMethod.POST)    
   public void show(@ModelAttribute("PredefinedPath") PredefinedPath predefinedPath)
        {
            //passing dto obj to service
             boolean res = service.savePredefinedPath(predefinedPath);
        }
}