spring - import resource is not working -


I have just started learning spring, it is easy to create multiple classes and values ​​in the spring configuration files Constructor RGR or Setters

What if I will reference the property of any other configuration file, then my simple program considers two classes of user and vehicle and two spring configuration files to FirstBean.xml and SecondBean.xml and an app class . The main method is as follows -

Directory structure -

 image

user.java -

  package com.common; Public class user {public string user name; Public vehicle vehicle; Public user () {} public string getUsername () {return user name; } Public Zero Set USUN (String Username) {this.username = Username; } Get Public Vehicle () {Return Vehicles; } Public Zero Set Vehicle (Vehicle Vehicle) {This. Vehicle = vehicle; }}   

Vehicles. Java -

  package com.common; Public category vehicle {The name of the public string vehicle; Public vehicles () {} public vehicles (string aerodynamics) {super (); This.vehicalname = vehicalname; }}   

App.java - Package Com Import com.common.User; Import org.springframework.context.ApplicationContext; Import org.springframework.context.support.ClassPathXmlApplicationContext; Public class app {public static zero main (string [] args throws interrupted expressions {// Todo auto-generated method stub applicationcontact reference = new classpath XML application context ("Com / Bean / FirstBein.xml"); User user = (user) context.getBean ("userClass"); String s = user.toString (); Println (s); }}

FirstBean.xml -

  & lt ;? xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" XSI: Schema location = "http: // Www .springframework.org / schema / beans http://www.springframework.org/schema/beans/spring-beans.xsd"> & Lt; Import Resources = "Com / Bean / Secondbin.xml" /> & Lt; Bean id = "user class" name = "user" class = "com.common.user" & gt; & Lt; Property Name = "User Name" Value = "Sushant" & gt; & Lt; / Property & gt; & Lt; Property name = "vehicle" ref = "vehicle class" & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; / Bean & gt;   

Seconds bin. Xml -

 ? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" XSI: Schema location = "http: // Www .springframework.org / schema / beans http://www.springframework.org/schema/beans/spring-beans.xsd"> & Lt; Bean id = "vehicalClass" name = "vehicle" category = "com.common.Vehical" & gt; & Lt; Constructor-RGR value = "pulsar" & gt; & Lt; / Constructor-RGR & gt; & Lt; / Bean & gt; & Lt; / Bean & gt; In FirstBean.xml, I have imported the resource of SecondBean.xml and referenced it using the referee but it is still not getting how it can be solved. I am not sure whether the work I am doing is possible or not.   

change & lt; Import Resources = "Second Bean .xml" />

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -