Micheal John John

Greenhorn
+ Follow
since Mar 02, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 Micheal John John

I am learning Spring Annotation and I want to know how each annotation works similair to the xml configuration.
Anyway, I want to use Spring without any xml file. So I started to use the JavaConfig.

In order to tell Spring, that we are using JavaConfig, we are using @Configuration.

Now I am just studying how the @Bean and @Autowired are working.

@Bean is for defining the bean which is similiar to the xml coniguration <bean></bean>

Below is my sample code, which is working fine for testing @Configuration and @Bean:



Output:
In Greeting Constructor
obj3 (com.example.service.Greeting@3043fe0e)
Hello Greeting Message


Now I want to use @Autowired in the above example:



Error: Not working!!!

Oct 15, 2016 2:49:04 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@439f5b3d: startup date [Sat Oct 15 02:49:04 SGT 2016]; root of context hierarchy
Oct 15, 2016 2:49:05 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7d417077: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor, org.springframework.context.annotation.internalCommonAnnotationProcessor,anotherConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,getGreet]; root of factory hierarchy
Exception in thread "main" obj3 (null)
java.lang.NullPointerException
at com.example.HelloApp.main(HelloApp.java:12)


I have googled and in one the example they have mentioned @AnnotationDrivenConfig is required for @Autowired to work, (http://www.basilv.com/psd/blog/2009/java-based-configuration-of-spring-dependency-injection)
I am using Spring 3.2, but @AnnotationDrivenConfig is not resolving and it seems not available?!!

So, I have tried other option of ComponentScan:


Output: Working with construtor injection

In Greeting Constructor
obj3 (com.example.service.Greeting@7a9273a8)
Hello Greeting Message


But why same thing not working with property setter?

Error:
Oct 15, 2016 2:54:41 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@439f5b3d: startup date [Sat Oct 15 02:54:41 SGT 2016]; root of context hierarchy
Oct 15, 2016 2:54:42 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1134affc: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor, org.springframework.context.annotation.internalCommonAnnotationProcessor,anotherConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,greeting,getGreet]; root of factory hierarchy
In Greeting Constructor
obj3 (null)
Exception in thread "main" java.lang.NullPointerException
at com.example.HelloApp.main(HelloApp.java:12)

4 years ago

I am new to Hystrix Dashboard. I have written sample application with Hystrix.
I want to see the Hystrix chart (command metric stream). But I am getting the below error:

Circuit: Unable to connect to Command Metric Stream
Thread Pools: Loading...




I am using STS with Maven.

Below is the code used:

Simple server microservice application (Spring boot web running in port 8085)




Simple client  microservice application (Spring boot web running in port 8095) I have included the dependency of Hystrix and Hystrix Dashboard along with Web, so all the Hystrix dependencies are in classpath






By running the above code, the hystrix is working fine, when the BooKStoreApplication is down, it is going to fallback method.

Both the urls are working fine.

Normal Case:

http://localhost:8085/recommended
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)

http://localhost:8095/to-read
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)




When BookStoreApplication is down (http://localhost:8085/recommended) accessing http://localhost:8095/to-read returns "Cloud Native Java (O'Reilly)" as expected.



But when I tried to invoke this url http://localhost:8095/hystrix, I am getting the Hystrix DashBoard Page and asking for the stream value.

I have tried given http://localhost:8095/ or http://localhost:8095/to-read, and clicked "Monitor Stream" and it is going to next page with error:


4 years ago
Hi All,
For one of my project, required to capture the audit history reports of all the activities of the users within the application.
We are using Servlet/JSP in J2EE environment.
For Ex: Whenever user updates some fields, we need to capture the Old value, new value, user id and time stamp. We have single form with more than 200 fields.
Just want to know the best way to do this..any frameworks available for it...or doing at the database side like using triggers..
6 years ago
I am just started learning on Socket programming and trying the below sample program in my local machine.

There should be 3 ports involoved in the below example program.





When the client trying to connect to the ServerSocket (4242), new random Socket port will be opened to serve the client and then ServerSocket again go to the wait state for the client request.
In the book it is mentioned "The Socket is on a different port than the ServerSocket, so that the ServerSocket can go back to waiting for other clients"

I want to print that port, the new random port which served the client request. I have just put lot of displays in both Client and server side socket object's as below..Am I missing something?









Server Output



Client Output

Thanks a lot Stephen and Jayesh. I started to explore more on this...
Hi all,

I am newbie and started to learn java and servlets.
I have below query, I am running webserver in port 80.
Client A connects to the webserver and requesting some file.
Client B connects to the webserver at the same time and requesting for some other / same file.

How the webserver exactly knows how to serve the intended client? Meaning not resulted in serving wrong files to wrong client. This is for HTTP case.

How about normal TCP..instead of running webserver...writing socket pgm...like I am running some standalone java pgm in special port say 905.
Client A directly connects to this port thru TCP and send some raw string for processing.
Client B also connects to this port. How will work in this case?