This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Get error in standalone AOP prog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Get error in standalone AOP prog" Watch "Get error in standalone AOP prog" New topic
Author

Get error in standalone AOP prog

Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 122
Hi I am learning Spring AOP
I have two Classes
1>CustomerService.java
public class CustomerService
{
private String name;
private String url;
public void setName(String name){
this.name = name;
}
public void setUrl(String url){
this.url=url;
}
public void printName(){
System.out.println("Customer name :"+this.name);
}
public void printURL(){
System.out.println("Customer website :"+this.url);
}
public void printThrowException(){
throw new IllegalArgumentException();
}
}
2>App.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main(String[] args)
{
ApplicationContext appContext =
new ClassPathXmlApplicationContext(new String[]{"Spring-Customer.xml"});

CustomerService cust =
(CustomerService)appContext.getBean("customerService");

System.out.println("****************************");
cust.printName();
System.out.println("*****************************");
cust.printURL();
System.out.println("*****************************");
try{
cust.printThrowException();
}catch(Exception e){
}
}
}
And a xml file--Spring-Customer.xml
<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-2.5.xsd">
<bean id="customerService" class="CustomerServices" >
<property name="name" value="Yong Mook Kim" />
<property name="url" value="http://www.mkyong.com" />
</bean>
<beans>
before compiling i have set these jars into classpath through a batch file run.bat in my class containing folder--
set classpath=.;D:\sjars\org.springframework.aop_3.0.5.RELEASE.jar;D:\sjars\org.springframework.asm_3.0.5.RELEASE.jar;D:\sjars\org.springframework.aspects_3.0.5.RELEASE.jar;D:\sjars\org.springframework.beans_3.0.5.RELEASE.jar;D:\sjars\org.springframework.context.support_3.0.5.RELEASE.jar;D:\sjars\org.springframework.context_3.0.5.RELEASE.jar;D:\sjars\org.springframework.core_3.0.5.RELEASE.jar;D:\sjars\org.springframework.expression_3.0.5.RELEASE.jar;D:\sjars\org.springframework.instrument.tomcat_3.0.5.RELEASE.jar;D:\sjars\org.springframework.instrument_3.0.5.RELEASE.jar;D:\sjars\org.springframework.jdbc_3.0.5.RELEASE.jar;D:\sjars\org.springframework.jms_3.0.5.RELEASE.jar;D:\sjars\org.springframework.orm_3.0.5.RELEASE.jar;D:\sjars\org.springframework.oxm_3.0.5.RELEASE.jar;D:\sjars\org.springframework.test_3.0.5.RELEASE.jar;D:\sjars\org.springframework.transaction_3.0.5.RELEASE.jar;D:\sjars\org.springframework.web.portlet_3.0.5.RELEASE.jar;D:\sjars\org.springframework.web.servlet_3.0.5.RELEASE.jar;D:\sjars\org.springframework.web.struts_3.0.5.RELEASE.jar;D:\sjars\org.springframework.web_3.0.5.RELEASE.jar;D:\sjars\commons-logging-api-1.1.1.jar

I compiled App.java
both App.java and CustomerService.java has compiled fine ,but when I run App.class it is giving these error--

D:\BroadHop\Docs\springinaction prog\aop>java App
May 26, 2011 11:05:34 AM org.springframework.context.support.AbstractApplication
Context prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationCont
ext@15eb0a9: startup date [Thu May 26 11:05:34 IST 2011]; root of context hierar
chy
May 26, 2011 11:05:35 AM org.springframework.beans.factory.xml.XmlBeanDefinition
Reader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Spring-Customer.xml
]
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefiniti
onStoreException: Line 12 in XML document from class path resource [Spring-Custo
mer.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-comp
lex-type.2.4.a: Invalid content was found starting with element 'beans'. One of
'{"http://www.springframework.org/schema/beans":import, "http://www.springframew
ork.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean,
WC[##other:"http://www.springframework.org/schema/beans"]}' is expected.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea
nDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReade
r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loa
dBeanDefinitions(AbstractXmlApplicationContext.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loa
dBeanDefinitions(AbstractXmlApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationCon
text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtain
FreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:397)
at org.springframework.context.support.ClassPathXmlApplicationContext.<i <br /> nit>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<i <br /> nit>(ClassPathXmlApplicationContext.java:93)
at App.main(App.java:9)
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid conten
t was found starting with element 'beans'. One of '{"http://www.springframework.
org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "
http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.spring
framework.org/schema/beans"]}' is expected.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Err
orHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErro
rReporter.reportError(XMLSchemaValidator.java:417)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportS
chemaError(XMLSchemaValidator.java:3181)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleS
tartElement(XMLSchemaValidator.java:1805)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startEl
ement(XMLSchemaValidator.java:705)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scan
StartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
MLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next
(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.
java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.
java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Doc
umentBuilderImpl.java:284)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocum
ent(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadB
eanDefinitions(XmlBeanDefinitionReader.java:388)
... 14 more

I put these two classes into packages ,I got same errors
I have tried this example from http://www.mkyong.com/spring/spring-aop-examples-advice/
Please suggest me what to do .
Thanks in advance
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Abhra Kar wrote:
<bean id="customerService" class="CustomerServices" >
<property name="name" value="Yong Mook Kim" />
<property name="url" value="http://www.mkyong.com" />
</bean>


Your java class is named CustomerService, here you give CustomerServices..
Anyway, it should have thrown ClassNotFoundFound Exception, if this was the case, so, i guess, there is some other thing wrong, which we have to correct before this..

Abhra Kar wrote:
I put these two classes into packages ,I got same errors

Don't tell, show us..

Abhra Kar wrote:
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefiniti
onStoreException: Line 12 in XML document from class path resource [Spring-Custo
mer.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-comp
lex-type.2.4.a: Invalid content was found starting with element 'beans'

Which is the 12th line, that is throwing this exception, Can you post the line or full xml..

P:S: please use code tags, it is very difficult to read without them..

Regards, Prasad
SCJP 5 (93%)
Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 122
<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-2.5.xsd">
<bean id="customerService" class="CustomerService" >
<property name="name" value="Yong Mook Kim" />
<property name="url" value="http://www.mkyong.com" />
</bean>
</beans>

----- I did not end the</beans>,previously I wrote <beans>
application is working fine
Thanks for your help , and sorry for my silly mistake
 
Consider Paul's rocket mass heater.
 
subject: Get error in standalone AOP prog
 
Similar Threads
CGLib error in "Before Advice" case
cvc-complex-type.2.3:Element 'beans' cannot have character [children] type's content type is element
The matching wildcard is strict, but no declaration can be found for element 'context:annotation'
using ClassPathXmlApplicationContext to load beans
[beans.xml] cannot be opened because it does not exist