This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

Himai Minh

Ranch Hand
+ Follow
since Jul 29, 2012
Cows and Likes
Cows
Total received
12
In last 30 days
0
Total given
0
Likes
Total received
68
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Himai Minh

Hi, Sam,
Can you try to annotate @EnableJpaRespositories(basePackages="sam.springboot.dao") in the CourseAPIdatabaseApp ?
This way, the repository can be enabled.
6 hours ago
Hello,
I would like to thank John Thompson, Dominik Cebula, Jesus and David Mayer for their great tutorials on Spring Framework 5.
This Spring forum and Spring Community forum are also helpful.
The books I highly recommends are Getting Started with Spring Framework 5 (4th edition), Spring In Action (4th and 5th).
Spring and Spring boot documents are must read.

Good luck to those who are taking the exam in the future.

Hi, Peter,
If the Dynamic JDK proxy is used, only public method can be proxied since we can only define public method in an interface.
And protected methods of the target object (the bean) cannot be called as this bean is called through its interface.

But if CGLib proxy is used, public and protected methods can be proxied.
2 weeks ago
Hi, in Getting Started with Spring Framework 5  4th edition , it says Spring AOP  only advices public joint point.
But as I tried , Spring AOP can advice protected or package friendly joint point like this:

@Before("execution(protected *  com..*(..))")
public void callBefore(){...}


Can anyone confirm me that Spring AOP can advice any joint point with any visibility except private?
2 weeks ago
Hi,  Wacc,
I got the same error when I signed up for this exam.
Did the bank call you or email you to confirm the payment?
If not, try to use debit card.
3 weeks ago
Hi , Geff Chang,
For Dominik's tutorial, there are only 3 modules out of 8 modules are available. I heard Dominik is still working on the 4th module.
During the meantime, you may consider to take John Thompson's Spring Core / Spring boot for the preparation.
Or, you can purchase practice exams written by David Mayer.
Hi, Stephan. Thanks for your suggestion.
I posted our discussion in the Spring community here : https://github.com/spring-projects/spring-framework/issues/23538
1 month ago
Hi, Stephan. Thanks for  your help. With my curiosity, I did this:








I expect an error as the doc says @Transactional annotation is not supposed to be inherited from the interface (BankAccountService).
But my output is still fine to my surprise.
1 month ago
Hi, Stephan,
In the AppConfig, I set proxyTargetClass=true. So, that means a CGLIB  class based proxy is created by extending the BankAccountServiceImpl.
So, Spring only "looks" at the class, not the BankAccountService interface when Spring uses AOP to create the transaction.
And the class should not inherit the @Transaction and it should throw an IllegalStateException. But it does not.
Correct me if I am wrong.
1 month ago
Hi, Stephan,
In the ServiceConfig.java, I change the return type from BankAccountService to BankAccountServiceImpl like this:

It still works fine to my surprise.
Output:


in create bank account, current trans status:org.springframework.transaction.support.DefaultTransactionStatus@628b819d



I guess the Spring container implementation does not follow what the specification said :


Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact that Java annotations are not inherited from interfaces means that if you are using class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), then the transaction settings are not recognized by the proxying and weaving infrastructure, and the object will not be wrapped in a transactional proxy, which would be decidedly bad.


1 month ago
Hi, I modified the ch 8 example of Getting Started With Spring Framework 4th.
I force to use class-based proxy for BankAccountServiceImpl. I expect this proxy won't inherit the @Transactional from BankAccountService.
But my demo at https://github.com/aCodeRancher/4thEdition/tree/myTrans/chapter%208/ch08-javaconfig-hibernate/src/main/java/sample/spring/chapter08/bankapp/service
shows me that the proxy of BankAccountServiceImpl does inherit the @Transactional.

The relevant code is :







The output should have an exception at TransactionInterceptor.currentTransactionStatus(). I expect the proxy won't inherit the Transaction. But to my surprise, it works. What do you think?


in create bank account, current trans status:org.springframework.transaction.support.DefaultTransactionStatus@5099c59b
current proxy: sample.spring.chapter08.bankapp.service.BankAccountServiceImpl@4c0e426a



Reference:
http://kim.saabye-pedersen.org/2013/05/spring-annotation-on-interface-or-class.html


1 month ago
Hi, in Spring doc

Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact that Java annotations are not inherited from interfaces means that if you are using class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), then the transaction settings are not recognized by the proxying and weaving infrastructure, and the object will not be wrapped in a transactional proxy, which would be decidedly bad.



It mentions "Java annotation are not inherited from interfaces".
But @Transactional API is meta-annotated by @Inherited. It can be inherited by children classes.
If that is the case, "Java annotation are not inherited from interfaces.... then the transaction settings are not recognized by the proxy" is not true for @Transactional.
Do you think this Spring doc needs to be updated?

I would like to ask you for opinion before I ask the Spring community.
2 months ago
I would recommend the Spring Community to update this part of the document.
But don't know any one from the community.
2 months ago
In this section, we have this :


The required attribute of @Autowired is recommended over the @Required annotation on setter methods.
The required attribute indicates that the property is not required for autowiring purposes. The property is ignored if it cannot be autowired.
...



I think it should be "required=false attribute indicates that the property is not required for autowiring purpose.
2 months ago
Hi,
I found you a simple example of replace web.xml by a Java class. The class extends AbstractAnnotationConfigDispatcherServletInitializer. In this class, you can specify the servlet config and root config.
https://www.mkyong.com/spring-mvc/gradle-spring-4-mvc-hello-world-example-annotation/

Another example is here:
https://www.boraji.com/spring-4-mvc-hello-world-example
2 months ago