Tu Dinh 15 Newbie Poster

Hi everyone,

I'm having trouble that always failed to deploy the Project:

This is Deployment Descriptor (web.xml):

<?xml version="1.0" encoding="UTF-8"?>

<web-app 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"
         version="2.5">
    <display-name>Eagle</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/Beans.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>Processor</servlet-name>
        <servlet-class>EITServletPackage.EITProcessorServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Processor</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <filter>
        <display-name>EITIssueProcessFilter</display-name>
        <filter-name>EITIssueProcessFilter</filter-name>
        <filter-class>EITServletPackage.EITIssueProcessFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>EITIssueProcessFilter</filter-name>
        <url-pattern>/Issue/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
</web-app>

Spring Application context file (Beans.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" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/eagleit"/>
        <property name="username" value="root"/>
        <property name="password" value=""/>
    </bean>

    <bean id="IssueJDBCTemplate" class="EITDAOPackage.EITIssueJDBCTemplate">
        <property name="dataSource"  ref="dataSource" />
    </bean>

</beans>

The JDBCTemplate class (EITIssueJDBCTemplate.java)

package EITDAOPackage;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import EITBeanPackage.EITIssueBean;

public class EITIssueJDBCTemplate implements EITIssueDAO 
{
    DataSource AppDataSource ;
    JdbcTemplate JDBCTemplate ;

    @Override
    public void SetDataSource(DataSource DS) 
    {
        this.AppDataSource = DS ;
        this.JDBCTemplate = new JdbcTemplate(DS) ;
    }

    @Override
    public void Insert(String Title, String Description, int Category)
    {

    }

    @Override
    public EITIssueBean GetIssue(int ID)
    {
        String SQLQuery = "SELECT * FROM issue where ID = ?" ;
        EITIssueBean ReturnIssue = 
                JDBCTemplate.queryForObject(SQLQuery, new Object[]{ID}, new EITIssueMapper()) ;

        return ReturnIssue;
    }

    @Override
    public void Update(int ID, String Title, String Description, int Category)
    {

    }

}

This is how I used the JDBCTemplate class (in a Filter class):

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException 
    {
        HttpServletRequest IssueRequest = (HttpServletRequest)request ;

        HttpSession IssueDataSession = IssueRequest.getSession() ;

        RequestDispatcher IssueViewDispatcher = 
                request.getRequestDispatcher("../IssueView.jsp") ;

        IssueDataSession.setAttribute("ID", 1) ;

        EITIssueJDBCTemplate IssueJDBCTemplate = 
                (EITIssueJDBCTemplate) TheContext.getBean("IssueJDBCTemplate") ;

        IssueViewDispatcher.forward(request, response) ;

        //chain.doFilter(request, response); COMMENTED OUT
    }

And finally the Error message I got:

13-Apr-2014 01:21:35.859 INFO [http-nio-8084-exec-7] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
13-Apr-2014 01:21:39.532 SEVERE [http-nio-8084-exec-7] org.apache.catalina.core.StandardContext.filterStart Exception starting filter EITIssueProcessFilter
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IssueJDBCTemplate' defined in class path resource [Beans.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [....]

I created this following tutorial from http://www.tutorialspoint.com/spring/spring_jdbc_example.htm

I think I did everything right and compliant with Spring configuration, but I don't know why NetBeans cannot deploy with the Beans.xml :(

Hope you guys can help me, just tell me if you need more information.

Much appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.