Spring Tutorial 16 - Writing a BeanFactoryPostProcessor

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ส.ค. 2024
  • In this tutorial, we'll learn about and write our own BeanFactoryPostProcessor. We'll also try out a handy BeanFactoryPostProcessor that comes with Spring: the PropertyPlaceholderConfigurer.

ความคิดเห็น • 78

  • @parth191079
    @parth191079 10 ปีที่แล้ว +53

    You are awesome, man! You might not know that how much you have helped people like me who does not have time to read bulky books to learn new technologies. Your videos are very neat and super easy to understand. You rock...!
    What's coming next?

  • @luciano5463
    @luciano5463 ปีที่แล้ว

    One can throw all the books away and follow only your classes awesome teacher !!!!

  • @ymgindia
    @ymgindia 10 ปีที่แล้ว +2

    Thanks Koushik, I find it very easy to understand.

  • @mrmogly1
    @mrmogly1 9 ปีที่แล้ว +2

    Very good tutorial and it is simplified way to understand Spring.

    • @jaroslavbeno
      @jaroslavbeno 9 ปีที่แล้ว

      +Bharath Kumar Lokaraj it is easy

  • @LeBadman
    @LeBadman 9 ปีที่แล้ว +10

    For those of you who are getting the FormatException error "Cannot convert String to int"
    -> Make sure you used curly braces {} and not brackets (), as you can see at 9:17.
    For those of you who are getting the error: Error creating bean with name 'triangle' defined in class path resource [spring.xml]: ... Failed to convert property value of type [java.lang.String] to required type [int] for property 'x'; nested exception is java.lang.NumberFormatException: For input string: "0;"
    -> Make sure you don't have semicolons ; for the values in your properties file.

    • @nenadnikolic3367
      @nenadnikolic3367 8 ปีที่แล้ว

      +LeBadman Thanks a lot man

    • @LeBadman
      @LeBadman 8 ปีที่แล้ว

      Nenad Nikolic You're welcome.

    • @HarshPatel-jo2xn
      @HarshPatel-jo2xn 6 ปีที่แล้ว

      instead try using PropertySourcesPlaceholderConfigurer

    • @priyamalik9505
      @priyamalik9505 6 ปีที่แล้ว

      I am still getting NumberFormatException.
      Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'x'; nested exception is java.lang.NumberFormatException: For input string: "${pointZero.pointX}"

    • @RamneekSingal40
      @RamneekSingal40 5 ปีที่แล้ว

      @@priyamalik9505 Please check the className definded in bean-

  • @MrErickongo
    @MrErickongo 9 ปีที่แล้ว +1

    really love your videos, thanks man !

  • @ushaprajapati9217
    @ushaprajapati9217 10 ปีที่แล้ว

    Thank you for your videos koushks, really its help me a lot to get to know spring framework....once again Thanks koushks.

  • @tipu7777
    @tipu7777 12 ปีที่แล้ว

    Its a great video Koushik , thanks for the good work, God bless you!

  • @puneethshivalingaiah
    @puneethshivalingaiah 9 ปีที่แล้ว

    Koushik Kothagal Thanks for your videos. You made it simple and clear:)

  • @pspraveen1
    @pspraveen1 12 ปีที่แล้ว

    Excellent Stuff.... very clear mind ....Really appreciate the efforts

  • @KentOJohnson
    @KentOJohnson 11 ปีที่แล้ว +1

    Thank you for your videos koushks! It would be nice to have an updated version for the new Spring 3 framework.

  • @gerardoei1102
    @gerardoei1102 10 ปีที่แล้ว +9

    As of version 3.1 I think you should use org.springframework.context.support.PropertySourcesPlaceholderConfigurer

    • @ankur7437
      @ankur7437 9 ปีที่แล้ว

      +Gerard Oei Thanks,it worked out for me.Was facing a issue due to this and not able to resolve

    • @DeepikaSharmaKannav
      @DeepikaSharmaKannav 8 ปีที่แล้ว

      Thanks for the suggestion. It resolved the issue for the "Cannot convert from String to int".

    • @a_rob
      @a_rob 4 ปีที่แล้ว

      Saved me from lot of toil googling! Thank you!

  • @manishsen195
    @manishsen195 7 ปีที่แล้ว +1

    If you are getting TypeMismatchException try any of the 3 given solutions below :
    1) Do not put properties values in Inverted comma ("")
    2) Do not give semi colon at the end
    3) Correct bean name is "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" .

  • @sonnix31
    @sonnix31 10 ปีที่แล้ว

    I'll not stop thanking you! so Thank You Sir.

  • @vyshnavramesh9305
    @vyshnavramesh9305 6 ปีที่แล้ว +4

    I miss my non-spring java soo much after going thru all these spring config...

  • @recoveringheart
    @recoveringheart 12 ปีที่แล้ว

    @GhavleVivek Just maximize the player. Click the button at the bottom right corner of the player. You can click full screen and the text becomes crystal clear.

  • @BikasKatwalK
    @BikasKatwalK 9 ปีที่แล้ว +4

    Java Brains Hello Kaushik - I have one query on this, lets say I have 2 properties file and I want to take the values from either property file based on some session value. how do I do that?
    Here I have a multi language system, so based on the value of language session i want to get the text from corresponding properties file.

  • @tipu7777
    @tipu7777 12 ปีที่แล้ว

    sorry about the last post, i had a silly mistake - its fixed now .. used ";" at the ned of value in properties file

  • @EmirPuska
    @EmirPuska 11 ปีที่แล้ว

    Man, you are great !!

  • @jeremynagel
    @jeremynagel 9 ปีที่แล้ว +2

    Your tutorial explains the mechanics well but I don't get one thing: What is the point of a PostProcessor? I don't understand why it is important to know this. Can you give a practical example of how this is used?

    • @jonh8800
      @jonh8800 9 ปีที่แล้ว

      You may need implement some logic, after the String container initializing a bean for example. :)

    • @Oblivion4eg
      @Oblivion4eg 8 ปีที่แล้ว +2

      +jeremy nagel maybe for you it's a late answer, for everyone else - think of the time you want to count how many times something was done: someone entered a page, someone requested a new calculation, etc.

  • @sujansai8116
    @sujansai8116 2 ปีที่แล้ว

    How can it be read that there is MyBeanFactoryPP class which implements the BeanFactoryPostProcessor interface and call the method inside it even before initializing the container? Because the Bean which is defined with class name MyBeanFactoryPP is inside the container right?

  • @mateuszalmannai5865
    @mateuszalmannai5865 12 ปีที่แล้ว

    Good stuff!

  • @TheGuroguro12
    @TheGuroguro12 7 ปีที่แล้ว

    Thank you very much

  • @rajarsh8345
    @rajarsh8345 9 ปีที่แล้ว +1

    If somebody's facing issue with, "Cannot convert from String to int" check in your property file, make sure you DONT use ";" after assigning the value to the variables in the file, if again you are having null pointer exception, then check that BeanFactoryPostProcessor should be implemented separately, it shouldn't be implemented along with any of the class.

  • @nandhakasi
    @nandhakasi 8 ปีที่แล้ว +1

    Property configuration is not working. I am version 4.2.6. Error that I am getting
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0' defined in class path resource [Spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'peopertyFile' of bean class [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]: Bean property 'peopertyFile' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    • @nandhakasi
      @nandhakasi 8 ปีที่แล้ว

      Identified the problem. For OOTB class, should be location for which I gave my own name.

    • @abhijeetzade3336
      @abhijeetzade3336 5 ปีที่แล้ว

      Properties path should b in forward slash then property file is readable

  • @sarikachugh6610
    @sarikachugh6610 7 ปีที่แล้ว

    I am able to manage to get output as per the placeholders substitution..But i am not getting the same result statement as per your output that is "Before bean initialization placeholder sustitution takes place very early so that ready spring.xml will be used by post processor etc..the way you got in your output some logs so to double check the output which i got as per the placeholder features that i added newly..

  • @vineettalekarr
    @vineettalekarr 11 ปีที่แล้ว

    I too get the number format exception even though the properties files is in the same location as the spring.xml .please help

  • @kalyanjiarava6623
    @kalyanjiarava6623 5 ปีที่แล้ว +1

    Is it mandatory to have bean factory post processor to use property place holder config

    • @divyagracie
      @divyagracie ปีที่แล้ว

      no, as you can see he removed it from spring.xml

  • @asing1313
    @asing1313 12 ปีที่แล้ว

    Oh sorry !!!!!
    The error in the below comment I have found. The error was I wrote the name of "PropertyPlaceholde­rConfigurer" class as "PropertPlaceholde­rConfigurer"
    I did not write the correct spelling

  • @shaofeiliu9404
    @shaofeiliu9404 7 ปีที่แล้ว +1

    you said "value" can be castered to primary types(include string).But "PropertiesLoaderSupport.setLocations(Resource ...)" the param is Resource , not string or primary type.

    • @reachmanav
      @reachmanav 6 ปีที่แล้ว

      Also, is "locations" a keyword? i.e. I tried with
      But it gives a weird exception:
      Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0' defined in class path resource [spring.xml]

  • @Neolkx
    @Neolkx 10 ปีที่แล้ว

    Have you added PropertyPlaceholderConfigurer to your xml configuration file? I'm using the same version and it works fine.

  • @aakashkanchan6868
    @aakashkanchan6868 6 ปีที่แล้ว

    Sir I have Question is that if make all java class in different packages like separate package for all POJO class and some more package for different functionality so in which package i should make class for BeanPostProcessor?Shouls I make it in different Package Also?.......Thanks in Advance

  • @mmnajar
    @mmnajar 11 ปีที่แล้ว

    What purpose does BeanFactoryPostProcessor serve? Where would be a place that overriding the method in BFPP would benefit us the best?

  • @sandeepdash123
    @sandeepdash123 12 ปีที่แล้ว

    Need to put the config file under src, same hierarchy as spring.xml. it will solve the issue.

  • @shardaprasad001
    @shardaprasad001 11 ปีที่แล้ว

    good one

  • @Faraz70
    @Faraz70 11 ปีที่แล้ว +1

    Great vidoes...can you recommend any good books for spring/hibernate? thanks

  • @amannitrr
    @amannitrr 8 ปีที่แล้ว

    I am not able to see the logs as shown in video 06:32 after beanfactory post process executes.... what would be reason for this?

    • @wilsoncardoso150
      @wilsoncardoso150 6 ปีที่แล้ว

      same here

    • @niharikapatnaik1199
      @niharikapatnaik1199 5 ปีที่แล้ว

      Can somebody pls help with the logs?

    • @niharikapatnaik1199
      @niharikapatnaik1199 4 ปีที่แล้ว

      Finally got the logs, after almost a year. I needed to use the earlier version of springs; used 4.2.2 instead of 5.2.2. Now I can see the info logs in the console. You can try with even older versions such as 3.2.

    • @niharikapatnaik1199
      @niharikapatnaik1199 4 ปีที่แล้ว

      @@wilsoncardoso150 Finally got the logs, after almost a year. I needed to use the earlier version of springs; used 4.2.2 instead of 5.2.2. Now I can see the info logs in the console. You can try with even older versions such as 3.2.

  • @asing1313
    @asing1313 12 ปีที่แล้ว

    Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.spring.framework.beans.factory.config.PropertPlaceholderConfigurer] for bean with name 'org.spring.framework.beans.factory.config.PropertPlaceholderConfigurer#0' defined in class path resource [spring.xml]; nested exception is java.lang.ClassNotFoundException: org.spring.framework.beans.factory.config.PropertPlaceholderConfigurer

  • @lavenderinmay
    @lavenderinmay 11 ปีที่แล้ว

    I am using spring 3.2.4, and I have the number format exception... I did exact what the video said. Is it because the framework version updated?

    • @reachmanav
      @reachmanav 6 ปีที่แล้ว

      You probably forgot to add "$" while mentioning the variables in spring.xml - "${pointA.pointX}"

    • @pallavikarpaklu2575
      @pallavikarpaklu2575 5 ปีที่แล้ว

      @@reachmanav I did exactly same. But i see type mismatch error :/

    • @pallavikarpaklu2575
      @pallavikarpaklu2575 5 ปีที่แล้ว

      Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'x'; nested exception is java.lang.NumberFormatException: For input string: "${pointA.pointX}"
      Caused by: java.lang.NumberFormatException: For input string: "${pointA.pointX}"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)

  • @tipu7777
    @tipu7777 12 ปีที่แล้ว

    i got this error, can you please help .. spring.xml and properties file in next comment
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'triangle' defined in class path resource [spring.xml]: ... Failed to convert property value of type [java.lang.String] to required type [int] for property 'x'; nested exception is java.lang.NumberFormatException: For input string: "0;"

  • @ruthggg
    @ruthggg 6 ปีที่แล้ว

    Hi,
    Can you explain please what the different between BeanPostProcessor and BeanFactoryPostProcessor?
    Thanks

    • @90AlmostFamous
      @90AlmostFamous 6 ปีที่แล้ว

      BeanFactoryPostProcessor gets called before beans are being instantiated, so because of that you can override or add properties. BeanPostProcessor gets called after beans have been instantiated.

    • @90AlmostFamous
      @90AlmostFamous 6 ปีที่แล้ว

      but im learing this too so i could be wrong

  • @syedtajammul3184
    @syedtajammul3184 8 ปีที่แล้ว

    does anyone get the same Value for triangle A as it is for triangle B

  • @benerjeeg9939
    @benerjeeg9939 11 ปีที่แล้ว

    nice

  • @nikhar1234tare
    @nikhar1234tare 4 ปีที่แล้ว

    what is the use of beanfactorypostproccesor

    • @manishakohli1540
      @manishakohli1540 4 ปีที่แล้ว +1

      It is used to perform certain operation pre and post the bean factory instantiation i.e when the bean factory setup is done, if we an operation to be performed, it can be added by using beanfactorypostprocessor. I Hope it helps!

  • @813jag
    @813jag 12 ปีที่แล้ว

    Hi,
    Thanks a lot for uploading such a nice video tutorial....
    throwing NumberFormat Exception while geting value from config propety file. saying can not convert string to int, I applied int parser as well still the exception is not resolved please help me.
    "exception is .TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'x'; nested exception is java.lang.NumberFormatException: For input string: "${pointA.pointX}"

  • @ruslanmostov7052
    @ruslanmostov7052 9 ปีที่แล้ว +1

    org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - this is working class path.

  • @Sciencefactory.
    @Sciencefactory. 12 ปีที่แล้ว

    Please make font size big and bold

  • @jorgesegundo4184
    @jorgesegundo4184 12 ปีที่แล้ว

    Buy Glasses LOL !

  • @god_bika
    @god_bika ปีที่แล้ว

    speak louder oufffff