I would like to use neo4j's embedded db on my web app.
Unfortunately I cannot use Spring.
Instead of instantiating a new db on each call, I'd rather inject a singleton.
How do I achieve this on Jetty ?
many thanks,
Not sure what exactly you are looking for, but I think you could inject a Neo4j instance into your servlet as a singleton via the servlets context?
Related
I'm new to Grails and was wondering if there was a way to populate some of my domain classes from web services rather than the DB managed by Grails.
RxGORM for REST is designed for exactly this task:
http://gorm.grails.org/latest/rx/rest-client/manual/index.html
I'm little confuse that if my project is on Spring and I want to use neo4j with java not with Spring Data .
what is a good practice ?
Thanks
You have another options for your Java app. I assume you are talking about client application, not about extension for Neo4j.
One option is to use REST API from your application. As a client you can use Jersey client and another REST client, which you like.
Another option is to use OGM, which is Object Graph Mapping Library, like Hibernate for rdbms. https://github.com/neo4j/neo4j-ogm
OGM for Neo4j is now separated from Spring : https://github.com/neo4j/neo4j-ogm. So you don't have to use Spring Data and can still use OGM (or even stick with Core Java API if you want). But Spring Data has some nice features (i.e. repositories) so if I were you I would give it a try.
If you're using spring, best practice would probably be to use spring-data-neo4j, because its integration with the rest of spring is quite nice. That being said, of course you don't have to. You have the options listed by others, and of course you can use the native Java API.
If you've already taken the step to use spring, in general I'd recommend using spring-data-neo4j unless you have a compelling specific requirement not to.
I'm replacing the service tier in an existing older Struts2 project with Spring service beans developed for another project.
I'd like to just #Inject these service beans into my Action classes.
Is it required to use Struts' Spring Plugin? Or can I add Spring into my Struts web application like I would any other (ContextLoaderListener, applicationContext.xml, context:component-scan)?
Am I missing some reason why the Struts Spring plugin helps me in another way?
Many thanks!
Well you can do the most of the things what you have described in your question as Services layer is completely out of view for the S2 and Struts2 do not care how you are creating your Service layer instances and other things.
Benefits i am seeing of using Struts2-Spring plugin is to delegate creation of Struts2 related things to Spring like Action classes creation,Interceptors,Results etc.
My Suggestion is to use the plugin as you are going to use the Spring in your application so its very good and flexible as well powerful to use the power of Spring DI to create required objects needed by S2 else S2 will use its own data creation factory to create framework component.
Why wouldn't you use the Spring plugin?
It's essentially invisible, uses Spring to create your actions (including injecting other Spring beans), etc.
Guice's #Inject doesn't know anything about Spring beans, AFAIK, so you'd be naming classes manually, they'd be instantiated via normal Java/Guice mechanisms, wouldn't be injected with their own Spring dependencies (unless you did it manually, or via AOP, or whatever).
You'd also need to use non-Spring mechanisms for doing injection in testing, which is fine, but unless you provide more details regarding your usecase, I don't really see a reason to bypass the functionality the Spring plugin provides out-of-the-box.
I have just implement some entities and some backing beans. However, I would like to know if there is someway to test the domain model, or entities, on the application server which in this case is Glassfish.
For example when I have added a new entity, I would like to test that the persistence is correct by writing and reading the entity and maybe do some operations.
I have used JUnit for standard applications, but now on a web application which is deployed on the application server makes me confused.
What is the standard way to deal with this. I have heard something about JSFUnit but I didn't see any example for Glassfish (maybe it doesnt matter?)
PS. My project involve EJB's, which I assume require either testing under an embedded application server or hosting server?
Can you please help me to understand what is the best practice to deal with this kind of stuff?
Best regards
Preferably you want out of container testing, which is very possible since JPA works outside of container. Just set up a new persistence.xml designed for testing, configured as if you were using Java SE only, and you can test your entities. You will have to set the entitymanager instance yourself thought, since you are not inside your container. Either let your test classes inherit from the EJB you are testing and set the protected EntityManager instance to an instance from your EntityManagerFactory, or add a setter to your EntityManager in each of your DAO EJBs. Then you should be ready to go. You will have to handle your transactions manually though, which should be possible to in the same way for most calls since you will probably want to rollback changes from each test.
I'd like to add some service method interceptor into my grails application. Interceptor should be a Spring managed object (it should be possible to inject whatever I want into it). and I want to specify which service/methods to intercept. As I understand it should be something like spring bean definition in 'conf/spring/resources.groovy', in other words, I'd like to use typical Spring approach. Strange, but I can't find any info on this topic.
Check out the Spring docs on AOP and this post http://www.objectpartners.com/2010/10/19/grails-plumbing-spring-aop-interceptors/