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

According to the quote:


@Autowired annotation doesn't work for beans that are themselves of collection or Map type. For instance, if you define a bean using util schema's map element, you can't autowire it using @Autowired annotation.



It refers to a bean that is a Map.  So, @Component MyMap is a bean and a Map type.
2 weeks ago
Hi, in Getting Started with Spring Framework 4th edition , in section 6-6 JSR 250's @Resource annotation, there is a quote:


@Autowired annotation doesn't work for beans that are themselves of collection or Map type. For instance, if you define a bean using util schema's map element, you can't autowire it using @Autowired annotation.


But as I tried , it works with @Autowired.




To my surprised, the output works fine. It should not work with @Autowired.


INFO  sample.spring.SampleApp - retrieving from my map : Maryland

3 weeks ago
Do you see any exception thrown when you insert data to a column that does not exist?
I am not familiar with Spring framework yet. But I guess the data is successfully committed to the price table in one transaction while the transaction for nos table fails.
1 month ago
Let me answer my own question.
I first created the QBankAccountDetails.java and QFixedDepositDetails.java and their classes by adding the dependencies below and changed the plugins:
In pom.xml:


...
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-mongodb</artifactId>
<version>3.6.6</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.7.4</version>
</dependency>
.....
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
                                                     <outputDirectory>target/generated-sources/java</outputDirectory>
  <processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>



Download Apache Maven. Set the path variables as instructed by MKyong (https://www.mkyong.com/maven/how-to-install-maven-in-windows/).
In a command prompt, navigate to the ch09-spring-mongo-data project folder. Type mvn compile. This can generate the Q-classes and java code in the target/generated-sources/java.
Copy the Q-classes , in this case, QBankAccountDetail.java  and QFixedDepositDetails.java to the corresponding package.

Close and delete the ch09-spring-mongo-data project from the Eclipse workspace. Open the original project with the original pom.xml file. Copy the Q classes to the corresponding package in the original project.
Now, the original project can compile with the Q classes.
Install MongoDB community instruction and follow their instruction to run it.
Run the BankApp.java from the original project. It should work.
1 month ago
Hi, I am running an example in ch 9 of Getting started with Springframework 4th edition:

pom.xml



NFO  org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3ecd23d9: startup date [Sat Jul 14 18:58:26 EDT 2018]; root of context hierarchy
Exception in thread "main" java.lang.NoSuchFieldError: logger
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:212)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:87)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at sample.spring.chapter09.bankapp.BankApp.main(BankApp.java:24)



The exception is thrown from the context.refresh. Please help.
1 month ago
Hi, in Getting Started with Spring Framework,4th edition, on p.108


<bean id="serviceTemplate" class="...ServiceTemplate" depends-on="baseService" abstract ="true"/>
<bean id="someService class="...SomeService" parent="serviceTemplate"/>
<bean id="someOtherService class="...SomeOtherService" parent="serviceTemplate"/>
<bean id="baseService" class=..."BaseServiceImpl"/>
In the above example isting, someService and someOtherService child bean definitions of serviceTemplate don't inherit the depends-on attribute from the serviceTemplate bean definition. As the String container creates beans in the order in which they are defined in the application context XML file, the baseService bean is created after the creation of someService and someOtherService.


I think the baseService bean is created before the the creation of someService , someOtherService and even serviceTemplate bean.
It is because the first bean in the above serviceTemplate bean depends on baseService. So, the Spring container should create baseService bean first before the serviceTemplate.
1 month ago
You can read Core JavaServer Faces 3rd edition for my information.
JSF has UI components that can be converted and validated.
And there are CDI beans and managed beans to save the properties from the inputs.
Also, JSF supports AJAX and security constraints such as authentication/authorization.
1 month ago
JSF
It is because the latest springboot is 2.0.3.RELEASE. (https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.0.3.RELEASE)
Do you have this in the pom.xm:


Also, are you running in JDK 8 ?
Here is a suggestion : https://www.mail-archive.com/users@maven.apache.org/msg140696.html
1 month ago
Hi, Roland.
You need to use Eclipse to create a maven project. Please see my attached image.
I recommend you to download Eclipse Oxygen.
Also, you need an updated pom.xml:

Your applicationContext.xml:

Please update the Test.java into this:


To run it,
1. right click on the project, select Maven->update project . This will download the latest spring framework.
2. right click Test.java, select "Run As" -> "Java Application".
3. Then, you will see it from the Eclipse console.
1 month ago
Hi,
Try to fix the pom.xml. Make sure the org.springframework.boot is version 2.0.3.BUILD-SNAPSHOT, instead of 2.1.0 as described.

The pom.xml is:

Make sure your password is correct in application.properties.
In my MySQL instance , my password is sesame.  (This DB is just for my own exercise and I can share the password.)
The tutorial's password is root, but your password may not be the same.
1 month ago
Let me answer my own question.
MKYong's example was based on a previous version of springframework core and JDK 5.
In his SpringBeans.xml, I added <context:component-scan base-package="com.mkyong.common"/> where the Person is in this package.
This is the modified SpringBeans.xml:


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context.xsd">
   
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

<context:component-scan base-package="com.mkyong.common" />
<bean id="customer" class="com.mkyong.common.Customer" >
<property name="action" value="buy" />
<property name="type" value="1" />
</bean>

<bean id="personA" class="com.mkyong.common.Person" >
<property name="name" value="mkyongA" />
</bean>
<bean id="personB" class="com.mkyong.common.Person" >
<property name="name" value="mkyongB" />
</bean>

</beans>



Now, it works as expected. The Person property in Customer object can be autowired to either PersonA or PersonB.
1 month ago
Hi, I am running MKYong's @Qualifier example at http://www.mkyong.com/spring/spring-autowiring-qualifier-example.
I am using the latest springframework core and JDK 10.





But it cannot autowire PersonB even though I put @Qualifier for the bean being autowired.


WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customer': Unsatisfied dependency expressed through field 'person'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.mkyong.common.Person' available: expected single matching bean but found 2: personA,personB
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customer': Unsatisfied dependency expressed through field 'person'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.mkyong.common.Person' available: expected single matching bean but found 2: personA,personB
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
....



1 month ago
Apress JPA Pro 2nd edition is worth to read. I read this book to pass my JPA certification exam.
But this book talks about JPA in general , not specific to Hibernate.
1 month ago
Hi, Pete and John Joe,
I install gradle plugin to my Eclipse Oxygen by following the example here https://www.youtube.com/watch?v=jEX8Wh1TLz4.
In the build.gradle, I include dependencies org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE.
I ran the hello.Application, it works.
I guess spring-boot-gradle-plugin:2.0.3 works , but not org.framework.boot 2.0.3.
2 months ago
Hi John Joe, I use the lastest org.framework.boot and I included the logback dependency in my pom.xm. When I ran the hello.Application in the tutorial in my previous post, it gave me an error saying that it cannot find the ch/qos/logback/core/joran/spi/JoranException.
But as I checked my Maven dependencies, this JoranException class is in one of the jar file.
But if I used the 1.5.10 version of org.framework.boot, it works.

This is my pom.xml:


Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException


2 months ago