http状态500 spring webservice hibernate

时间:2014-01-02 17:07:57

标签: java spring web-services hibernate

我的状态为http 500,它说服务器遇到内部错误,无法完成此请求。但是apache日志根本没有显示任何错误。

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

servlet的context.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
    <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <beans:property name="driverClassName" value="org.postgresql.Driver"/>
            <beans:property name="url" value="jdbc:postgresql://localhost:5432/tms"/>
            <beans:property name="username" value="postgres"/>
            <beans:property name="password" value="paswoord"/>
        </beans:bean>

        <beans:bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <beans:property name="dataSource" ref="dataSource" />
            <beans:property name="configLocation">
                <beans:value>classpath:hibernate.cfg.xml</beans:value>
            </beans:property>
            <beans:property name="configurationClass">
                <beans:value>org.hibernate.cfg.AnnotationConfiguration</beans:value>
            </beans:property>
            <beans:property name="hibernateProperties">
                <beans:props>
                    <beans:prop key="hibernate.dialect">${jdbc.dialect}</beans:prop>
                    <beans:prop key="hibernate.show_sql">true</beans:prop>
                </beans:props>
            </beans:property>
        </beans:bean>
        <tx:annotation-driven />
        <beans:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <beans:property name="sessionFactory" ref="sessionFactory" />
        </beans:bean>
    <context:component-scan base-package="be.pxl.publictms" />
</beans:beans>

testController getUsers方法部分工作我可以打印结果,但不会将其作为填充列表返回。

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import be.pxl.publictms.model.Computer;
import be.pxl.publictms.pojo.Gebruiker;
import be.pxl.publictms.service.GebruikerService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;


@Controller
@RequestMapping("test")
public class TestController {

    @Autowired
    private GebruikerService gebruikerService;

    @RequestMapping(value = "pc",method = RequestMethod.GET)
    public @ResponseBody Computer testMethod() {
        return new Computer(0, "DELL");
    }

    @RequestMapping(value = "users",method = RequestMethod.GET)
    public @ResponseBody List<Gebruiker> getUsers(){
        List<Gebruiker> users = gebruikerService.getGebruikers();
        System.out.println("***********************************************");
        for(Gebruiker user: users){
            System.out.println(user.toString());
        }
        System.out.println("***********************************************");
        /*List<Gebruiker> users = new ArrayList<Gebruiker>();
        users.add(new Gebruiker(1, "laurens", "test"));
        users.add(new Gebruiker(2, "laurens", "test"));
        users.add(new Gebruiker(3, "laurens", "test"));*/
        return users;
    }
}

GebruikerService:

import be.pxl.publictms.DAO.GebruikerDAO;
import be.pxl.publictms.pojo.Gebruiker;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author 11302785
 */
@Service
public class GebruikerServiceImpl implements GebruikerService{

    @Autowired
    private GebruikerDAO gebruikerDao;

    @Transactional
    public void addGebruiker(Gebruiker gebruiker) {
        gebruikerDao.addGebruiker(gebruiker);
    }

    @Transactional
    public List<Gebruiker> getGebruikers() {
        return gebruikerDao.getGebruikers();
    }

    @Transactional
    public void deleteGebruiker(int id) {
        gebruikerDao.deleteGebruiker(id);
    }

    @Transactional
    public void updateGebruiker(Gebruiker gebruiker) {
        gebruikerDao.updateGebruiker(gebruiker);
    }
}

gebruikerDAO:

import be.pxl.publictms.pojo.Gebruiker;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author 11302785
 */
@Repository
public class GebruikerDAOImpl implements GebruikerDAO{

    @Autowired
    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public void addGebruiker(Gebruiker gebruiker) {
        sessionFactory.getCurrentSession().save(gebruiker);
    }

    @Override
    public List<Gebruiker> getGebruikers() {
        return sessionFactory.getCurrentSession().createQuery("from Gebruiker").list();
    }

    @Override
    public void deleteGebruiker(int id) {
        Gebruiker gebruiker = (Gebruiker)sessionFactory.getCurrentSession().load(Gebruiker.class, id);
        if(null != gebruiker){
            sessionFactory.getCurrentSession().delete(gebruiker);
        }
    }

    @Override
    public void updateGebruiker(Gebruiker gebruiker) {
        sessionFactory.getCurrentSession().update(gebruiker);
    }

}

pojo class gebruiker(它是荷兰语,意思是用户......对不起它的荷兰语部分):

import java.util.HashSet;
import java.util.Set;

/**
 * Gebruiker generated by hbm2java
 */
public class Gebruiker  implements java.io.Serializable {


     private int gebruikerid;
     private Werknemer werknemer;
     private String gebruikersnaam;
     private String paswoord;
     private Set<Bericht> berichtsForGebruikerid = new HashSet<Bericht>(0);
     private Set<Bericht> berichtsForOntvangerid = new HashSet<Bericht>(0);
    public Gebruiker() {
    }


    public Gebruiker(int gebruikerid, String gebruikersnaam, String paswoord) {
        this.gebruikerid = gebruikerid;
        this.gebruikersnaam = gebruikersnaam;
        this.paswoord = paswoord;
    }
    public Gebruiker(int gebruikerid, Werknemer werknemer, String gebruikersnaam, String paswoord, Set<Bericht> berichtsForGebruikerid, Set<Bericht> berichtsForOntvangerid) {
       this.gebruikerid = gebruikerid;
       this.werknemer = werknemer;
       this.gebruikersnaam = gebruikersnaam;
       this.paswoord = paswoord;
       this.berichtsForGebruikerid = berichtsForGebruikerid;
       this.berichtsForOntvangerid = berichtsForOntvangerid;
    }

    public int getGebruikerid() {
        return this.gebruikerid;
    }

    public void setGebruikerid(int gebruikerid) {
        this.gebruikerid = gebruikerid;
    }
    public Werknemer getWerknemer() {
        return this.werknemer;
    }

    public void setWerknemer(Werknemer werknemer) {
        this.werknemer = werknemer;
    }
    public String getGebruikersnaam() {
        return this.gebruikersnaam;
    }

    public void setGebruikersnaam(String gebruikersnaam) {
        this.gebruikersnaam = gebruikersnaam;
    }
    public String getPaswoord() {
        return this.paswoord;
    }

    public void setPaswoord(String paswoord) {
        this.paswoord = paswoord;
    }
    public Set<Bericht> getBerichtsForGebruikerid() {
        return this.berichtsForGebruikerid;
    }

    public void setBerichtsForGebruikerid(Set<Bericht> berichtsForGebruikerid) {
        this.berichtsForGebruikerid = berichtsForGebruikerid;
    }
    public Set<Bericht> getBerichtsForOntvangerid() {
        return this.berichtsForOntvangerid;
    }

    public void setBerichtsForOntvangerid(Set<Bericht> berichtsForOntvangerid) {
        this.berichtsForOntvangerid = berichtsForOntvangerid;
    }
    @Override
    public String toString(){
        return this.gebruikersnaam + " " + this.paswoord;
    }
}

0 个答案:

没有答案
相关问题