Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Spring RESTful Client/Server tutorial

  1. #11

    Default

    Quote Originally Posted by Itf View Post
    I used this example and I have a problem. here is the error stack :

    javax.servlet.ServletException: Could not resolve view with name 'jaxbView' in servlet with name 'LabResult'
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1029)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)


    You need two things:

    1.

    <!-- Resolve views based on string names -->
    <bean class="org.springframework.web.servlet.view.BeanNa meViewResolver" />


    2.

    <!-- XML view using a JAXB2 marshaller -->
    <bean id="jaxbView" class="org.springframework.web.servlet.view.xml.Ma rshallingView">
    <constructor-arg ref="jaxbMarshaller" />
    </bean>


    And

  2. #12
    Join Date
    Feb 2011
    Posts
    3

    Default

    I did all of that, here is my labresult-servlet.xml

    <?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="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/tx
    http://www.springframework.org/schem...ing-tx-2.5.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">


    <bean
    class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" />
    <bean
    class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter" />

    <!-- JAXB2 marshaller. Auto-magically turns beans into xml -->
    <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="classesToBeBound">
    <list>
    <value>org.msclinic.labresult.beans.ResultProfil es
    </value>
    <value>org.msclinic.labresult.beans.ResultProfil e
    </value>
    <value>org.msclinic.labresult.beans.Results</value>
    </list>
    </property>
    </bean>
    <bean id="labresult"
    class="org.springframework.web.servlet.view.xml.Ma rshallingView">
    <constructor-arg ref="jaxbMarshaller" />

    </bean>
    <bean
    class="org.springframework.web.servlet.view.Conten tNegotiatingViewResolver">
    <property name="mediaTypes">
    <map>
    <entry key="xml" value="application/xml" />
    <entry key="html" value="text/html" />
    </map>
    </property>
    <property name="viewResolvers">
    <list>
    <bean class="org.springframework.web.servlet.view.BeanNa meViewResolver" />
    <bean class="org.springframework.web.servlet.view.UrlBas edViewResolver">
    <property name="viewClass"
    value="org.springframework.web.servlet.view.JstlVi ew" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />

    </bean>
    </list>

    </property>
    </bean>

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbcostgresql://localhost:5432/labDB" />
    <property name="username" value="sa" />
    <property name="password" value="passwordPASSWORD" />
    </bean>

    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="annotatedClasses">
    <list>
    <value>org.msclinic.labresult.beans.ResultProfil e
    </value>
    </list>
    </property>

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect"> org.hibernate.dialect.PostgreSQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    </props>
    </property>
    </bean>

    <bean id="myUserDAO"
    class="org.msclinic.labresult.service.dao.impl.Res ultServiceDAOImpl">
    <property name="sessionFactory" ref="mySessionFactory" />

    </bean>

    <bean name="labResults"
    class="org.msclinic.labresult.web.controller.LabRe sultController">
    <property name="userDAO" ref="myUserDAO" />
    </bean>

    <!-- ANNOTATION DRIVEN TRANSACTIONS -->
    <bean id="txManager"
    class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="myDataSource" />
    </bean>
    <tx:annotation-driven transaction-manager="txManager" />
    </beans>

    and 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">
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/LabResult-servlet.xml
    </param-value>
    </context-param>

    <servlet>
    <servlet-name>LabResult</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>LabResult</servlet-name>
    <url-pattern>*.list</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

    the index page get displayed as it doesn't pass through the servlet but all other pages gives the same error

  3. #13

    Default

    Please use code tags when displaying code. Also, could it be that you only map ".list" operations in your web.xml?

  4. #14
    Join Date
    Feb 2011
    Posts
    3

    Default

    Thanks Toxic,
    I wanted to only map ".list". Should I map any thing else? in my controller, I only need ".list"
    here is my controller:
    Code:
    @Controller
    public class LabResultController {
    
    	private ResultServiceDAO resultServiceDAO;
          @Autowired
    	public void setResultServiceDAO(ResultServiceDAO resultServiceDAO) {
    		this.resultServiceDAO = resultServiceDAO;
    	}
          @RequestMapping(method = RequestMethod.GET, value = "/labresult.list")
    	public ModelAndView myRestMethod() {
    
    		result = resultServiceDAO.getResultProfileByResultId(0);
    		if (!result.isEmpty()) {
    
    			return new ModelAndView("labresult", "response", result);
    		} else
    			return null;
    	}
    }

  5. #15

    Default

    It seems that either your spring-config is not picked up properly or that your controller mappings are not. I'm not sure whether there's case-sensitivity involved in your servlet (e.g., try naming it lowercase "labresult"). In the latter case, you should also supply the beans

    Code:
    <context:component-scan base-package="my.controller.package"
    <annotation-driven/>
    Last edited by Toxic; Feb 24th, 2011 at 11:38 AM.

  6. #16
    Join Date
    May 2011
    Posts
    4

    Default

    That was a great post. Nice work. Even two years later, it is one of the more concise write-ups I have seen.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •