Categories
discuss

Correct usage Of LOG4J in Spring Framework Via DI

I am trying to use Log4j as part of the Spring Framework, as far as i understand through the use of a an appropriate bean the system is supposed to map a singleton instance accessible in the code while mapping the logging depth automatically to the class

Similar to the normal use of Log4J as in

Logger log = Logger.getLogger(getClass());

i have been using the following Spring bean definition

<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"
        value="org.springframework.util.Log4jConfigurer" />
    <property name="targetMethod" value="initLogging" />
    <property name="arguments">
        <list>
            <value>conflog4j.xml</value>
        </list>
    </property>
</bean>

But i am unable to map this bean to a specific member in a given class nor am i able to use it through @autowired

Please let me know if there are any better ways to integrate Log4j and Spring

Best Regards

Mark

Answer

The short answer to your question is that log4j is not DI friendly.

The Log4jConfigurer.initLogging() method has a void return value, so there’s nothing to inject. The idea is that you call that method, which bootstraps log4j, and then you use the Log4j API as usual (using Logger.getLogger(getClass())).

You generally wouldn’t configure Log4jConfigurer as a Spring bean, though, but more usually you’d invoke it directly from your own code during application startup.

If this is a webapp, then Spring provides alternatives to Log4jConfigurer that are better suited to that environment (Log4jWebConfigurer, Log4jConfigListener).

Incidentally, 2 years ago I filed a feature request to allow loggers to be autowired, and it’s finally been marked as fix for Spring 3.1. Horray.

Categories
discuss

Can class be abstract even if does not have any abstract methods? If yes Whats the use?

I have a doubt regarding HttpServlet class is an abstract class even though there is not any abstract method in the class , all methods are concrete.
Can class be abstract even if does not have any abstract methods? If yes Whats the use?

Thanks

Answer

In the case of HttpServlet, the point is that servlet programmers typically don’t want their servlet to support all 4 oft the main HTTP methods (POST, GET, PUT, DELETE), so it would be annoying to make the doGet(), doPost(), etc. methods abstract, since programmers would be forced to implement methods that they don’t need. Therefore, HttpServlet provides a default implementation for all those methods that does nothing except return an error statuscode to the client. Programmers can override the methods they need and not worry about the rest. But actually using the HttpServlet class itself make no sense (since it does nothing useful), so it’s abstract.

And there you have a great example for when it can make sense to have an abstract class without any abstract method.

Categories
discuss

Is there an equivalent to php.net for JavaScript? [closed]

I am looking for an equivalent to the php.net manual (http://us3.php.net/manual/en/) but for javaScript methods and syntax.

Is there a single site that lists out all the javaScript functions available in a clear and concise manner as php.net provides for the PHP language?

Answer

Mozilla Developer Central with its Core JavaScript Reference is a good resource. But as JavaScript is object-oriented, the reference is object-oriented too and there is no overview of all functions/methods.

And if you want to did deeper into how JavaScript works, I recommend to read the ECMAScript specification, the standardized language dialects like JavaScript and JScript are derived from.

Categories
discuss

Run GATE pipeline from inside a Java program without the GUI. build a tomcat app with gate

i have built some plugin components to GATE and in combination with ANNIE tools, im running a pipeline in GATE platform.

Does anyone know how can i run a pipeline from the console? I want to build a web application in Tomcat that will be taking a plain text from the web page, passing it to the GATE pipeline i have built and do something. So i need to run GATE in a simple Java file, how can it be done?

Thanks in advance and sorry for my poor grammar

Answer

The GATE example code shows you how to run GATE in a number of different ways, in particular the Goldfish example illustrates how to run GATE from the command line.

Categories
discuss

Add marker on touched location using google map in Android

How do I add a marker on a particular location in the map?

I saw this code that shows the coordinates of the touched location. And I want a marker to pop or be shown in that same location every time it is touched. How do I do this?

public boolean onTouchEvent(MotionEvent event, MapView mapView) {   
    if (event.getAction() == 1) {                
        GeoPoint p = mapView.getProjection().fromPixels(
            (int) event.getX(),
            (int) event.getY());
            Toast.makeText(getBaseContext(), 
                p.getLatitudeE6() / 1E6 + "," + 
                p.getLongitudeE6() /1E6 , 
                Toast.LENGTH_SHORT).show();

            mapView.invalidate();
    }                            
    return false;
}

Answer

You want to add an OverlayItem. The Google Mapview tutorial shows how to use it.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..