Win a copy of Event Streams in Action this week in the Java in General 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, 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.
1 week ago
I would recommend the Spring Community to update this part of the document.
But don't know any one from the community.
1 week 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 weeks 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 weeks ago
By the way, as I checked the API in org.springframework.transaction.annotation, @Transactional annotation has a meta-annotation @Inherited. That means this annotation can be inherited from interface. The class that implemented with an interface annotated with @Transactional should be able to create a transaction in AOP framework.
But I don't know why the Spring doc says the class based proxy won't see the @Transactional.
1 month ago
First, do you see a pop up message like the first JPG when you open your Spring_Config.xml?
If so, click on the "Configure application context" link.
Then, you will see a checkbox next to the file path. Click on it , just like my second JPG.
1 month ago
Hi,
Maybe, try to open your Spring_Config.xml file, and see if there is a pop up message telling your to add this config file to the application context. If so, click on it and see.
Then, clean your project and compile it.
I guess your current problem is that the bean is not registered in the application context.
1 month ago
Hi,
In Spring doc, it says

"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.



I have a question regarding to the interface-based proxy and how it can see the @Transaction.
Suppose I have :



During runtime, the Spring AOP framework will generate a proxy for the GoodBankService:


According to the Spring doc above, putting @Transactional annoation in the interface works for the interfaced-based proxy (GoodBankServiceProxy). But it also says "Java annotations are not inherited from interfaces..."

My question is if GoodBankServiceProxy class does not inherit the @Transactional annotation from the BankService interface, how can this proxy execute the target object's openAccount method in the transaction ?

1 month ago
Hi,
Maybe, try to put your Spring_Config.xml under resource/META_INF/config folder.
After you compile it, make sure under target/classes/META-INFO/config folder has your Spring_Config.xml

I guess the reason why your bean is not found because the Spring_config.xml is not in the target/classes/META-INFO folder.
1 month ago
Hi, Labzar,
Is there any Spring Practice Exam desktop version?
The one you shared with us is on Android.
Hi,
From the Pivotal's study guide of Spring 5 professional certification exam, I don't see it mention Spring WebFlux or reactive programming which are new to Spring 5.
Are they on the exam?
Just want to confirm with some of you who took the exam.
Hi, Dominik,
I just bought your tutorial module 1 and I am studying on it  now
I can't wait to see module 2 - 8 available. Would you mind posting them soon?
Thanks.
Hi, I came across two examples from Spring in Action and Getting Started with Spring Framework.
One example uses new ClassPathXmlApplicationContext ("META-INFO/spring/knight.xml") and the other one uses new ClassPathXmlApplication("classpath:META-INFO/spring/applicationContext.xml")
Both knight.xml and applicationContext.xml are in resources/META-INFO/spring.
Both example works
I assume classpath prefix is always needed as the xml config file is under resources/META-INFO folder.
But why the classpath is needed in one example, but not the other?
The examples are here:
https://github.com/habuma/spring-in-action-4-samples/blob/master/Chapter_01/knight/src/main/java/sia/knights/KnightMain.java
https://github.com/getting-started-with-spring/4thEdition/blob/master/chapter%206/ch06-bean-profiles/src/main/java/sample/spring/chapter06/bankapp/BankAppWithProfile.java

Thanks in advance.
3 months ago
Hi, I find a fix to my code, but I don't think my fix is perfect. If anyone has a better solution, please let me know.
In the applicationContext.xml, I add the viewResolver:


This is my bankapp-servlet.xml


I committed my code there :
https://github.com/aCodeRancher/4thEdition/tree/my-bank-app/chapter%2012/ch12-bankapp
4 months ago
Hi, I am trying to replace web.xml in ch12-bankapp example of Getting Started With SpringFramework 4th edition.
This is the web.xml provided in the book:


I converted it into Java code:



This is the Tomcat 9 log :


I cannot get any result from the browser.
If anyone knows, please help. Thanks.
This is my detailed code in GitHub:
https://github.com/aCodeRancher/4thEdition/tree/master/chapter%2012/ch12-bankapp
4 months ago