Meeting 5: Unterschied zwischen den Versionen
(→Links) |
(→Springframework) |
||
Zeile 98: | Zeile 98: | ||
Wow, you're unnecessarily angry about this. Aren't there walhes being poached in the ocean, people dying in Darfur, or other causes better served by your unmitigated fury? With regard to XML config: At first I thought this was bad because, I believed the config file was used to be able to change things out without having to recompile the jar, but then I realized that was ridiculous and not a viable use case. That doesn't sound accurate. Of course you can change an XML file without having to recompile anything, and there are totally viable use cases for this specifically IMO. I've seen a few in action.On a side note, I also agree that XML config is kind of a pain in the ass and I like the annotation-based config for many use cases, but on this point I'm not sure I agree with you (or maybe I just don't understand what your exact point is).As for this one: now I realize their are passionate developers out there like Bob who want to bring Java back to it’s roots and give it frameworks that work within the language instead of around the language . Assuming you are describing Spring, I'm not sure I agree with this either. If you ask me, Spring works around JEE APIs more than it works around the Java language itself. In fact, Java's introspection capabilities and dynamic class instantiation facilitate Spring's IoC model, so there's a symbiotic relationship in there somewhere.*dons flame-retardant jodhpurs in preparation for response* - max | Wow, you're unnecessarily angry about this. Aren't there walhes being poached in the ocean, people dying in Darfur, or other causes better served by your unmitigated fury? With regard to XML config: At first I thought this was bad because, I believed the config file was used to be able to change things out without having to recompile the jar, but then I realized that was ridiculous and not a viable use case. That doesn't sound accurate. Of course you can change an XML file without having to recompile anything, and there are totally viable use cases for this specifically IMO. I've seen a few in action.On a side note, I also agree that XML config is kind of a pain in the ass and I like the annotation-based config for many use cases, but on this point I'm not sure I agree with you (or maybe I just don't understand what your exact point is).As for this one: now I realize their are passionate developers out there like Bob who want to bring Java back to it’s roots and give it frameworks that work within the language instead of around the language . Assuming you are describing Spring, I'm not sure I agree with this either. If you ask me, Spring works around JEE APIs more than it works around the Java language itself. In fact, Java's introspection capabilities and dynamic class instantiation facilitate Spring's IoC model, so there's a symbiotic relationship in there somewhere.*dons flame-retardant jodhpurs in preparation for response* - max | ||
− | + | Well, I was gonna tell you how much I liked the flip flop shot but instead I tell you how much I relaly like the butterfly shot and the shot of the boys playing together in the water. O -yeah that flip flop shot is SO GROOVY!, LOL. It's so nice to see your family up on your post | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Gallery== | ==Gallery== |
Version vom 16. Dezember 2012, 05:21 Uhr
When: Monday, October 13th, 2008 - 19:00
Where: Freihaus HS4
In what follows we provide a simple formal model of this process. ,
Inhaltsverzeichnis
Guice
Download the slides (pdf, 115KB).
You can also view the slides online.
Download the sourcecode (pdf, 13KB).
Basic facts
Of course theory is nice, but it becomes useful when you start using a concret technology which enables dependency injection for you, such the Google Guice framework presented by Jan Zarnikov. It provides a pure Java style (no external XML configuration which makes it possible to misstype a name; refactorings also changes configuration!) with all Java5 features such as generics (type safety) and annotations (injecting is realized via Guice own annotations).
Cześć, to jest komentarz.Aby skswoaać komentarz po prostu zaloguj się i wyświetl komentarze do wpisu, gdzie znajdują się opcje ich edycji oraz usuwania.
Simple example
The following chapter shows a simple application with a database connection and a mocked connection for its unit tests:
The UserController
class is subject of the JUnit test and requires a database (in fact, just something that implements the DAO
interface). Because unit tests should only test a certain unit (and not the database management system or anything else), the controller class will get another implementation of DAO
injected if it is run by JUnit (namely TestDAO
instead of JdbcDAO
).
Injecting objects is just as easy as annotating the constructor with the @Inject
annotation (you could also have used it at the field itself, or provided a setter method):
<source lang="java">
public class UserController {
private final DAO dao;
@Inject public UserController(DAO dao) { this.dao = dao; }
public boolean login(String username, String password) { List<User> users = this.dao.getUsers(); // ... }
} </source>
Of course you also have to configure your dependencies somewhere:
<source lang="java">
public class AppModule extends AbstractModule {
public void configure() { bind(DAO.class).to(JdbcDAO.class); }
}
public class TestModule extends AbstractModule {
public void configure() { bind(DAO.class).to(TestDAO.class); }
} </source>
To startup the Guice framework, you have to do following first:
<source lang="java">
public class MyApplication {
public static void main(String[] args) { // configure Guice with AppModule Injector injector = Guice.createInjector(new AppModule());
// userController already got its proper DAO instance injected UserController userController = injector.getInstance(UserController.class);
boolean isLoggedIn = userController.login("Foo", "Bar"); }
} </source>
Or use your special configuration for unit test:
<source lang="java">
public class UserControllerTest {
private UserController userController;
@Before public void setup() { // configure Guice with TestModule, instead with AppModule Injector injector = Guice.createInjector(new TestModule()); this.userController = injector.getInstance(UserController.class);
´ }
// some tests...
} </source>
Wow, you're unnecessarily angry about this. Aren't there walhes being poached in the ocean, people dying in Darfur, or other causes better served by your unmitigated fury? With regard to XML config: At first I thought this was bad because, I believed the config file was used to be able to change things out without having to recompile the jar, but then I realized that was ridiculous and not a viable use case. That doesn't sound accurate. Of course you can change an XML file without having to recompile anything, and there are totally viable use cases for this specifically IMO. I've seen a few in action.On a side note, I also agree that XML config is kind of a pain in the ass and I like the annotation-based config for many use cases, but on this point I'm not sure I agree with you (or maybe I just don't understand what your exact point is).As for this one: now I realize their are passionate developers out there like Bob who want to bring Java back to it’s roots and give it frameworks that work within the language instead of around the language . Assuming you are describing Spring, I'm not sure I agree with this either. If you ask me, Spring works around JEE APIs more than it works around the Java language itself. In fact, Java's introspection capabilities and dynamic class instantiation facilitate Spring's IoC model, so there's a symbiotic relationship in there somewhere.*dons flame-retardant jodhpurs in preparation for response* - max
Well, I was gonna tell you how much I liked the flip flop shot but instead I tell you how much I relaly like the butterfly shot and the shot of the boys playing together in the water. O -yeah that flip flop shot is SO GROOVY!, LOL. It's so nice to see your family up on your post
Gallery
Thanks to Jan for providing these pictures.