I am working on a web application which will serve as an SQL injection learning platform with multiple levels in spring boot and react. I am using PostreSQL as my main database, but I also wanted a lightweight solution for a vulnerable database on which the injections will occure. I was going to choose H2, but it isn't supported on Heroku where I wanted to deploy my application, as I worked with it in the past and it's already familiar.
So the question is: What other platform could I use to work with H2 or should I choose something else instead of H2, and if yes, what?
The way I handle this is to use spring-bean "profiles"
default
or
!default
I use H2 all the time for local-development mode (using 'default' spring bean profile to achieve this).
Now, we do not over-use spring-profiles. We have default and !default. And that is is.
All my JPA stuff works with H2.
Related
I would like to know, is there any possible way to connect to any database during the runtime of a Java Spring Boot application? I am going to use database information from the user (from frontend).
I know something alternatively related to this,
AbstractRoutingDatasource: https://www.baeldung.com/spring-abstract-routing-data-source
I am using Spring Data MongoDB 2.2.1.RELEASE for MongoDB access. And flapdoodle embed mongo 2.2.0 as embedded MongoDB for testing. This setup works fine. But recently, I have added support for Spring transactions. And since, MongoDB supports transactions only on replica sets. I have created a replica set locally on my machine and tested transaction scenarios. All good till now. But now when I run my unit tests, #Transactional annotation added to service methods is breaking the application with below error since the embedded MongoDB is not a replica set.
com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected
My question is how to configure my application so the #Transactional feature does not break my application when using embedded or standalone MongoDB?
Suggestions much appreciated. Thanks !!
It is possible to run a 1-node replica set. You may consider this especially in tests so that your test environment more closely resembles your production one.
I am using JDBC drivers in java action class file to access database in struts 2. But as mentioned on this website there is another way to access database in struts using tag in struts.xml file. But that is not working for me in struts 2. My question is is there any other more efficient way to access database in struts2 other than using JDBC drivers because I have to make connection each time I access any action class file? And I am not using hibernate only want to use Struts.
In a Java EE Web Application, database connections should be managed and pooled inside an EJB, the war should know nothing about the datasource or the database connection details.
If you can choose which technology to include in your Web App, I strongly suggest to let Spring manage your database connections.
Example of Struts2 + Spring integration.
Note: Spring libraries have nothing to do with Spring MVC, that is a framework alternative to Struts2.
Edit
Things change and nowadays for persistence / ORM I suggest pure Java EE's JPA2 over Spring.
I want to see the tables of my Play! application with the H2 console, but all I see is a list of internal tables of the db engine. How can I view the tables of my application?
Log on to the JDBC URL jdbc:h2:mem:play instead. That is where the development database runs on at least on my Play instance.
Most likely, you are looking a different database. Could you verify the database URL is really jdbc:h2:~/play?
You should also consider upgrading to a more recent version of H2. The version you are using (1.3.149) is a beta version.
Can i use Spring Webflow/MVC and Spring Security and Hibernate on Google App Engine?
Is there a list/summary of java frameworks that can be used on the GAE?
Will it Play In Java lists frameworks, languages and libraries that work (or not) in Google App Engine. At present, the information listed is:
Spring MVC
Version 2.5.6
Status COMPATIBLE
To see Spring's MVC framework running on App Engine, check out the autoshoppe sample application. If you're using Spring forms (e.g. using the spring-form.tld tag library and subclassing SimpleFormController), you will need to register custom editors for your properties. This is covered in http://groups.google.com/group/google-appengine-java/browse_thread/thread/d93fd7385bf85bf7.
Spring ORM
Version 2.5.6
Status COMPATIBLE
To get Spring working with the App Engine-provided JPA interface, follow the instructions at http://objectuser.wordpress.com/2009/05/19/spring-jpa-in-google-app-engine/, which discusses a workaround to the dependency on javax.naming needed for #PersistenceContext. A more complex workaround is available at http://groups.google.com/group/google-appengine-java/browse_thread/thread/187d41712ec1d394.
Spring Security
Version(s) ?
Status SEMI-COMPATIBLE
To work around a ClassNotFoundException, you can use a re-compiled version of the library which adds a StringInsensitiveComparator class -- the download is provided at http://www.google-app-engine.com/blog/post/Spring-security-fix-for-google-app-engine.aspx. See http://www.dotnetguru2.org/bmarchesson/index.php?p=1100 for tips on how to get Spring Security running with App Engine and GWT (in French). See http://groups.google.com/group/google-appengine-java/browse_thread/thread/964e7f5e42840d9c for discussion on the integration.
Hibernate
Versions All
Status INCOMPATIBLE
You cannot currently use Hibernate directly. The differences between the App Engine datastore and SQL were too great to get the standard Hibernate up and running under App Engine. App Engine does support JDO and JPA, so you may be able to convert your Hibernate code to use one of these ORM interfaces.
I suppose that it should work with Spring 3.0 too, I will try soon and share the results.
UPDATE: I tried a Spring MVC Hello World with Spring 3.0.6 with Google App Engine and it worked perfectly, both locally and in the cloud. The drawback though, is longer load time when a new instance starts.
As far as I know, no third party libraries are supported (at least none are listed), and JRE classes are limited to this list. But I guess if a library only makes use of the listed jre classes, they should be fine. However, finding out if they do would have to be based on trying it out.