Announcement Announcement Module
Collapse
No announcement yet.
Need help adding mysql support Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help adding mysql support

    I have got a skeleton working but once I start adding the datasource I run into context=null errors.

    I'm using portlet mvc and annotations if that helps. I'm truly thinking this is a matter of getting the exact formula down with the applicationContext, web.xml, portlet,xml, etc... files meshing together properly.

    My application is a notification system and the objective is to query a mysql database with a select statement to retrieve notices.

    I have my application.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
    
    <beans>
    
    	<bean id="noticesService" class="edu.southwestern.notices.service.NoticesServiceImpl" />     
    	
    	<bean id="parameterMappingInterceptor" class="org.springframework.web.portlet.handler.ParameterMappingInterceptor"/>
    
    	 <!-- Default View Resolver -->
            <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
                    <property name="prefix" value="/WEB-INF/jsp/"/>
                    <property name="suffix" value=".jsp"/>
            </bean>
     	
     </beans>
    Here is my notices-portlet.xml file:
    Code:
    <beans 	xmlns="http://www.springframework.org/schema/beans" 
           	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		xmlns:p="http://www.springframework.org/schema/p"        
           	xmlns:context="http://www.springframework.org/schema/context"
        	xsi:schemaLocation="http://www.springframework.org/schema/beans 
           						http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        						http://www.springframework.org/schema/context 
           						http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    
    	<context:annotation-config/>
    	<bean id="noticesViewController" class="edu.southwestern.notices.portlet.NoticesViewController" />
    	
    	<bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping" />		
    	
    </beans>
    Here is my notices-dao.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
    
    <beans>
    	<!--DataSource -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        	<property name="driverClassName" value="com.mysql.jdbc.Driver" />    	
           	<property name="url"><value>jdbc:mysql://url/database</value></property>    	
        	<property name="user"><value>user</value></property>    	
        	<property name="password"><value>password</value></property>    	        
        </bean>
    	
    </beans>
    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
      <description>CampusNotices portlet mvc application</description>  
      
      <context-param> 
        <param-name>contextConfigLocation</param-name>  
        <param-value>
        	/WEB-INF/context/applicationContext.xml
            /WEB-INF/context/notices-dao.xml
        </param-value> 
      </context-param>    
      <listener> 
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
      </listener>
      
      <servlet>  
        <servlet-name>CampusNotices</servlet-name>    
        <display-name>CampusNotices Wrapper</display-name>    
        <description>Automated generated Portlet Wrapper</description>    
        <servlet-class>org.jasig.portal.container.PortletServlet</servlet-class>    
        <init-param>
          <param-name>portlet-class</param-name>
          <param-value>org.springframework.web.portlet.DispatcherPortlet</param-value>
        </init-param>    
        <init-param>
          <param-name>portlet-guid</param-name>
          <param-value>CampusNotices.CampusNotices</param-value>
        </init-param>    
      </servlet>  
      
      <servlet> 
        <servlet-name>ViewRendererServlet</servlet-name>  
        <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class> 
      </servlet>  
          
      <servlet-mapping>
        <servlet-name>CampusNotices</servlet-name>
        <url-pattern>/CampusNotices/*</url-pattern>
      </servlet-mapping>  
           
      <servlet-mapping> 
        <servlet-name>ViewRendererServlet</servlet-name>  
        <url-pattern>/WEB-INF/servlet/view</url-pattern> 
      </servlet-mapping>
      
      <taglib xmlns=""> 
        <taglib-uri>http://java.sun.com/portlet</taglib-uri>  
        <taglib-location>/WEB-INF/tld/portlet.tld</taglib-location> 
      </taglib>   
    </web-app>
    and my portlet.xml file
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <portlet-app
        xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
        version="1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
                            http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
                            
         <portlet>     
            <portlet-name>CampusNotices</portlet-name>        
            <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>        
            
            <init-param>
                <name>contextConfigLocation</name>
                <value>/WEB-INF/context/notices-portlet.xml</value>
            </init-param>
          
            <supports>
                <mime-type>text/html</mime-type>
                <portlet-mode>view</portlet-mode>           
            </supports>        
            
            <portlet-info>
                <title>Campus Notices</title>
            </portlet-info>  
        </portlet>    
        
    </portlet-app>

    Can anyone spot what I'm doing wrong? Or perhaps is there a library file that I'm not including.

    Thanks.

  • #2
    I made some adjustments to my code below.

    First of all, my notices-dao.xml file was incorrect. The property name is not 'user' it is 'username'.

    Secondly, I removed the reference to notices-dao.xml out of my applicationContext.xml file and placed it inside the notices-portlet.xml file.

    Now, I am no longer getting the context is null error but now I'm receiving the following error:
    Caused by: org.jasig.portal.PortalException: javax.portlet.PortletException: Request processing failed
    at org.jasig.portal.channels.portlet.CPortletAdapter. getMarkup(CPortletAdapter.java:613)
    at org.jasig.portal.channels.portlet.CPortletAdapter. renderCharacters(CPortletAdapter.java:511)
    ... 7 more
    Caused by: javax.portlet.PortletException: Request processing failed
    at org.springframework.web.portlet.FrameworkPortlet.p rocessRequest(FrameworkPortlet.java:496)
    at org.springframework.web.portlet.FrameworkPortlet.d oDispatch(FrameworkPortlet.java:453)
    at javax.portlet.GenericPortlet.render(GenericPortlet .java:178)
    at org.apache.pluto.core.PortletServlet.dispatch(Port letServlet.java:218)
    at org.apache.pluto.core.PortletServlet.doGet(Portlet Servlet.java:158)
    Caused by: java.lang.NullPointerException
    at edu.southwestern.notices.service.NoticesServiceImp l.getNotices(NoticesServiceImpl.java:14)
    at edu.southwestern.notices.portlet.NoticesViewContro ller.viewNotices(NoticesViewController.java:30)


    I'm thinking that my dao layer is not being found here is my NoricesServiceImpl file:

    Code:
    package edu.southwestern.notices.service;
    
    import edu.southwestern.notices.dao.INoticesDao;
    import edu.southwestern.notices.domain.Notices;
    import edu.southwestern.notices.service.INoticesService;
    
    
    public class NoticesServiceImpl implements INoticesService {	
    	private INoticesDao noticesDao = null;
    
    	public Notices getNotices(String sdate) {
    		return noticesDao.getNotices(sdate);
    	}
    }
    I also made the following adjustment to my notices-dao.xml file by adding the following line after the dataSource bean:

    Code:
        <bean id="noticesDao" class="edu.southwestern.notices.dao.NoticesDaoImpl">
        	<property name="dataSource" ref="dataSource" />
        </bean>


    I know this is a shot in the dark. I'm having a really tough time finding documentation with portlet mvc and dao combined (mysql in particular)...too many resources that seem to be not relative to exactly what I'm doing but feel that I am piecing together things that may not go together. If you think there is documentation out there that could help me that would be great. Right now, I am using the Spring Recipes book to help me through this.

    Thanks.

    Comment

    Working...
    X