Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
尝试使用下拉菜单中的hibernate从数据库获取数据时发生Spring mvc错误505_Spring_Hibernate_Jsp_Spring Mvc - Fatal编程技术网

尝试使用下拉菜单中的hibernate从数据库获取数据时发生Spring mvc错误505

尝试使用下拉菜单中的hibernate从数据库获取数据时发生Spring mvc错误505,spring,hibernate,jsp,spring-mvc,Spring,Hibernate,Jsp,Spring Mvc,我在尝试启动应用程序时遇到困难,我被困在代码中的某个地方 我的实体类是: @Entity @Table(name="metalocation") public class Location implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="ID") private in

我在尝试启动应用程序时遇到困难,我被困在代码中的某个地方

我的实体类是:

@Entity
@Table(name="metalocation")
public class Location implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
private int id;
@Column(name="DB_ID")
private String dbId;
@Column(name="GEO_LAT")
private double geoLAT;
@Column(name="GEO_LNG")
private double geoLNG;
@Column(name="IN_LOCATION")
private int inLocation;
@Column(name="ISO")
private String iso;
@Column(name="LOCAL_NAME")
private String localName;
@Column(name="TYPE")
private char type;

@OneToMany(cascade=CascadeType.PERSIST)
@JoinColumn(name="meta_address_fk")
private Set<Address> address;

public Location() {

}
.......... All setters and getters
//控制器错误

        com.platformhouse.clinicsystem.web.controller.PatientSignupController.getCountries(PatientSignupController.java:40)


----------


    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

您忘记为您的服务添加
@Autowired
注释。这就是为什么会出现
NullPointerException
。请在下面查看

@Autowired
private PatientService patientService;
@Autowired
private AddressService addressService;
更新

您已经将其称为
@Service(“地址服务”)
。addressService拼写不正确。
将其更改为
@Service(“addressService”)

与另一个cuse相同的错误:org.springframework.beans.factory.BeanCreationException:创建名为“PatientsSignupController”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连接字段:private com.platformhouse.clinicsystem.web.service.AddressService com.platformhouse.clinicsystem.web.controller.PatientSignupController.AddressService;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为的符合条件的bean
@Repository
@Transactional
public class AddressDAO {


@Autowired
private SessionFactory session;

public void setSession(SessionFactory session) {
    this.session = session;
}

public Session session(){
    return session.getCurrentSession();
}

@SuppressWarnings("unchecked")
public List<Location> getAllCountries() {
    Query query =   session().createQuery("from Location where inLocation <=246");
      List<Location> results = query.list();
      return results;
     }  
  }
@Controller
@RequestMapping(value = "/usersignup")
public class PatientSignupController {

private PatientService patientService;
private AddressService addressService;


@RequestMapping(value = "/usersignup")
public String signup() {
    return "usersignup";
}


@RequestMapping( method = RequestMethod.GET)
public List<Location> getCountries() {

    return this.addressService.getAllCountries();

}
}
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/mydb" />
      <property name="username" value="username" />
      <property name="password" value="password" />
</bean>

    <context:component-scan base-package="com.platformhouse.clinicsystem.web.dao">
</context:component-scan>


<!-- Hibernate 4 SessionFactory Bean definition -->
<bean id="hibernate4AnnotatedSessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
      <property name="annotatedClasses">
          <list>

<value>com.platformhouse.clinicsystem.web.model.entity.User</value>
            <value>com.platformhouse.clinicsystem.web.model.entity.UserType</value>
            </value>
            <value>com.platformhouse.clinicsystem.web.model.entity.Location
            </value>
            <
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
            </prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="javax.persistence.validation.group.pre-persist">com.platformhouse.clinicsystem.web.validation.PersistenceValidationGroup
                </prop>
                <prop key="javax.persistence.validation.group.pre-update">com.platformhouse.clinicsystem.web.validation.PersistenceValidationGroup
                </prop>
                <prop key="javax.persistence.validation.group.pre-remove">com.platformhouse.clinicsystem.web.validation.PersistenceValidationGroup
                </prop>
        </props>
    </property>

        <property name="packagesToScan">
            <list>
                <value>com.platformhouse.clinicsystem.web.dao</value>
                <value>com.platformhouse.clinicsystem.web.service.implementation</value>
            </list>
        </property>
</bean>


<tx:annotation-driven transaction-manager="transactionManager" />


    <bean id="exceptionTranslator"
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor">
    </bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</bean>
<form method="Get">
        <label>Country/region:</label>

        <select id="iCountry" name="iCountry">
        <c:forEach items="${locationList}" var="country">
        <option selected="selected" value="">please select country</option>
                                            <option value="${country.id}">${country.localName}</option>
                                        </c:forEach>
                                        <select />
      HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException


   **type Exception report
   message Request processing failed; nested exception is java.lang.NullPointerException
   description The server encountered an internal error that prevented it from fulfilling this request.
   exception
   org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   root cause
     java.lang.NullPointerException


----------
        com.platformhouse.clinicsystem.web.controller.PatientSignupController.getCountries(PatientSignupController.java:40)


----------


    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
@Autowired
private PatientService patientService;
@Autowired
private AddressService addressService;