Post new topic   Reply to topic
Author Message
douglasmhurst
Registered Member
Registered Member


Joined: Sep 30, 2006
Posts: 276

Is it you intention to produce a spring MVC tutorial.

I've tried to implement some of the tutorials I've seen elsewhere and they don't seem to fit with the MyEclipse addition of Spring capability to web and/or java projects.

I'm curious why MyEclipse defaulst applicationContext.xml to src (with deployment to classes) instead of placing it in WEB-INF.

In your DWRSpringJPAExample, applicationContext.xml is placed in the WEB-INF directory and even if you change .springbeans and .classpath, it can't be placed anywhere else and work properly. Weird!

It would be nice if Spring implementation could be consistent.
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23817

There are no immediate plans for an MVC tutorial, but any pending ones out there should work fine -- please provide specific problems that you ran into like actions not working an examples so we can try and reproduce here.

Also, the location of the Spring file can be different places -- direct manipulation of .classpath and .springbeans is probably sub-optimal, as you can do the same thing directly from the UI under project properties > MYEclipse > Spring and setup the config file(s) there.

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
douglasmhurst
Registered Member
Registered Member


Joined: Sep 30, 2006
Posts: 276

If you mean project properties > MyEclipse > Add Spring Capabilitiies, try the following.

Instead of placing applicationContext.xml in "src", put it in WEB-INF when adding Spring capability.

Now, when creating a bean, put in a line like

beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));

... and tell me if the beanFactory is instantiated or if you get an error saying you can't find applicationContext.xml in the classpath. Also, after you've added Spring capability, you can't go back to project file > MyEclipse > Add Spring Capability because it's no longer visible. How could I change it from "src" to "WEB-INF" after my initial add?

I'm going to the feature request area to ask that the entire Spring capability thing be made more consistent.
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23817

Quote:

If you mean project properties > MyEclipse > Add Spring Capabilitiies, try the following.

I don't, nor is there such a menu item. Right-click on the project, go down to Properties, then down to MyEclipse, then down to Spring -- under Bean sub menu you can setup the config files that contribute to the bean validation and content assist in MyEclipse. (see screenshot)

Quote:

Instead of placing applicationContext.xml in "src", put it in WEB-INF when adding Spring capability.

Now, when creating a bean, put in a line like

beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));

... and tell me if the beanFactory is instantiated or if you get an error saying you can't find applicationContext.xml in the classpath. Also, after you've added Spring capability, you can't go back to project file > MyEclipse > Add Spring Capability because it's no longer visible. How could I change it from "src" to "WEB-INF" after my initial add?


No it doesn't work nor would I expect it to -- you are placing a file outside of the classpath, then using an instance of ClasspathResource to try and load it. You know this already, so I'm not sure the point you are trying to make.

As I mentioned in my last post, you will need to use a different kind of AbstractResource implementation from the Spring APIs to load this resource, most likely a ServletContextResource that loads with dir references from the root of a web app.

Quote:

I'm going to the feature request area to ask that the entire Spring capability thing be made more consistent.

We welcome that feedback, but please be specific about what isn't consistent and what needs to be changed and what your expectations are.

Adding Spring capabilities to a project will help you make certain assumptions about the project, like where the original bean config files live and what libraries to add to the build path -- this has *nothing* to do with how the Spring code runs once deployed.

If you are going to move where the Spring bean configuration files live, you need to change your Spring code accordingly to load those resources as noted above -- MyEclipse doesn't care where you put these files as long as you tell it about them (in the Bean config page) so it can provide validation and content-assist for you -- but there is a difference of design-time-tooling and runtime-behavior here... the two don't impact each other and I think that is where the confusion is coming form.

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
revanthg



Joined: Dec 21, 2009
Posts: 4

accountdaoinf.java
----------------------------
package com.nit.spring.dao;

public interface AccountDAOInf {
float getBalance(int ano);
}
accountdao.java
----------------------------
package com.nit.spring.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.sql.DataSource;

public class AccountDAO implements AccountDAOInf {

DataSource ds;

public AccountDAO(DataSource ds) {
super();
this.ds = ds;
}

public float getBalance(int ano) {
float bal=0;
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
con=ds.getConnection();
ps=con.prepareStatement("select balance from account where accno=?");
ps.setInt(1,ano);
rs=ps.executeQuery();
if(rs.next())
bal=rs.getFloat(1);
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
if(ps!=null)
ps.close();
if(con!=null)
con.close();
}
catch(Exception e){
e.printStackTrace();
}
}
return bal;
}
}
daolayer.java
----------------------
package com.nit.spring.dao;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class DAOLayer {


public static void main(String[] args) {
BeanFactory factory=new XmlBeanFactory(new FileSystemResource("src/applicationContext.xml"));
AccountDAOInf dao=(AccountDAOInf)factory.getBean("acc");
System.out.println("balance in the account is :rs" +dao.getBalance(1001));

}

}
applicationContext.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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean name="ds" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:server"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
</bean>
<bean name="acc" class="com.nit.spring.dao.AccountDAO">
<constructor-arg ref="ds"></constructor-arg>
</bean>
</beans>



output
---------
i got this exception




log4j:WARN No appenders could be found for logger (org.springframework.util.ClassUtils).
log4j:WARN Please initialize the log4j system properly.
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))))
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at com.nit.spring.dao.AccountDAO.getBalance(AccountDAO.java:24)
at com.nit.spring.dao.DAOLayer.main(DAOLayer.java:13)
Caused by: java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:323)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:260)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
... 3 more
balance in the account is :rs0.0
 
 View user's profile Send private message  
Reply with quote Back to top
support-joy
Registered Member
Registered Member


Joined: Feb 03, 2009
Posts: 3441

revanthg,

Your current issue is not related to this post. It is development related.
Quote:

log4j:WARN No appenders could be found for logger (org.springframework.util.ClassUtils).
log4j:WARN Please initialize the log4j system properly.

Can you check your log4j properties?
Quote:

org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))))
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

Your issue is related to connection pooling. The connection is being refused. Look into BasicDataSource.java:855 and BasicDataSource.java:540, this should point you to the problem at hand.

_________________
Joy
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
All times are GMT - 6 Hours
Post new topic   Reply to topic
® 2014 - Genuitec, LLC.