Spring MVC using Google Cloud Platform MySQL Database - mysql

I am trying to use GCP flexible environment for my Spring MVC demo app. I have created a MySQL database on GCP and my app is connected to it via pom.xml as described here Using Cloud SQL for MySQL. But I cant find info how to use Spring configuration XML file with this MySQL database. Should I use both pom.xml and spring_config.xml data source bean to connect to it or just pom.xml? BTW I am using ComboPooledDataSource:
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

Its good to maintain both. Generally pom is for maven dependencies and config file is for all configuration related tasks like db connectivity.

Related

Spring Batch integration with spring cloud data flow on local server to add spring admin capabilities

I have a basic spring batch app that runs on embedded Apache Tomcat in spring boot. I need to add spring admin capabilities to it. As per latest spring docs, I need to use spring cloud data flow to do this (https://docs.spring.io/spring-batch-admin/). So now I need to use spring cloud dataflow and integrate my spring batch app on local server. I just want it to run on my local machine under tomcat without deploying it to any cloud environments like cloud foundry or openshift. Is it possible? I am sure its possible. I would like to get some references/Examples on this type of integration and starter guide integrating spring batch app. Do I need to create tasks in spring cloud data flow to run my spring batch app? If there are any sample examples/pseudo code to guide me then it would be easy.
As described in the migration-guide, you can use the "local" variant of Spring Cloud Data Flow (SCDF) as a replacement to Spring Batch Admin (SBA).
SCDF is a simple Spring Boot application that you can run it as a standalone Java process similar to how you're running the application today.
Also, as described in the migration-steps, you'd have to port your existing batch workload to Spring Cloud Task model, and that should be a straightforward process - use this Spring Batch sample. To the most part, you'd copy/paste the business logic into a Spring Cloud Task application and all the infrastructure including schemas, repository, and other batch goodies will continue to work. There are few complex implementations in task-app-starers, which can be used as a reference, too.
Lastly, you can use SCDF's dashboard for monitoring and management.

Eureka's hsqldb overriding MySQL

I have a Spring Boot project that currently consists of three microservices (all of them are maven children of the mentioned project), namely:
eureka-server : as the name says, it's simply a Eureka project that works as a server for registering other microservices
user-server : a project that holds a 'monolithic stack' (model, DAO, service and controller). Here is where the problem is. More on this later.
web-server : a project that contains the AngularJS application and a controller that is accessible from AngularJS and that communicates with the user-server module.
Eureka forces me to include a hsqldb dependency in the parent pom in order to launch the three mentioned applications.
The problem is that I was using MySQL in user-server and hsqldb has somehow overriden the MySQL data source.
In other words, the database engine of user-server is now hsqldb and I want to keep working with MySQL, and if I remove the dependency, the application will obviously not launch.
Is there any way to solve this and work with, maybe, two databases in user-server?
Thank you everyone!
I finally figured out how to get it working. I'll just post it here in case someone faces a similar problem.
It seems that application.properties wasn't being read when launching the application because telling Spring Boot which .yml configuration file for Eureka should be read, it was overriden.
In the .yml file of the microservice I wasn't able either to set the datasource to MySQL, so the solution was to hardcode the datasource properties when launching the microservice, as follows:
System.setProperty("spring.datasource.platform","mysql");
System.setProperty("spring.datasource.url","jdbc:mysql...");

Spring Integration - FTP is not working with OpenShift

I have used Spring Integration FTP to copy files from an FTP server to local and processing it. It is working fine with local using Spring Boot and Spring Integration, but I have deployed the application in OpenShift, but it is not looking for the FTP files.
For example:
In local FileReadingMessageSource is getting invoked
[task-scheduler-5] o.s.i.file.FileReadingMessageSource : Created message: [GenericMessage [payload=file-temp\abcd.xml, headers={id=30e5289a-aba6-19db-1d81-3036fca251b0, timestamp=1464675579294}]]
But it is not invoked in OpenShift. Is there any special configuration required for it to work?
As per the Linux team, OpenShift is not supporting FTP Client and it is not possible to run FTP using Spring Integration in OpenShift.

Use c3p0 with JBOSS AS 7.1.1

I read in c3p0´s manual link that it is possible to use c3p0 library inside JBOSS as an MBean.
Once configured correctly, I would like to reference the new C3P0PooledDataSource in my Java WAR through its JNDI name. As I am using Spring
it would be something similar to:
[src/webapp/WEB-INF/applicationContext.xml]
<jee:jndi-lookup id="dataSource" jndi-name="java:PooledDS" />
However, I don´t know how to configure this library properly. I tried to place c3p0-0.9.2.1.jar and c3p0-service.xml in the folders commented in the manual
but I had no luck.
I am currently developing a project which uses a MySql database, so I have instaled the mysql connector inside the JBOSS AS 7.1.1 server.
I have to say that if I integrate c3p0 and MySql connector in my project I can deploy it correctly. So...:
Is it possible to use c3p0 connection pool inside JBOSS AS 7.1.1 as described in its manual? How should I configure it?
I started to "play" with c3p0 because of its large number of configuration properties, but I don´t know if c3p0 is better than embedded JBOSS pooling capabilities.
Does c3p0 library deserve to be used instead of JBOSS embedded connection pool (i.e. configuring a datasource with the admin console/web) ?
I appreciate any comments to these matters.
Thanks in advance.

Lightswitch + WCF RIA + MySQL connector/Net almost working but not quite

I'm trying to connect to an existing MySQL DB from Lightswitch RTM through a WCF RIA service.
I did the following:
Install MySQL connector version 6.3.7 from MySQL developer zone on my development machine. The lastest version 6.4.3 does not seem to work and gives an error "Out of sync with server" when establishing a connection from within Visual Studio.
Test the connection from Visual Studio by creating a new data connection, selecting MySQL database as provider, and providing the MySQL server IP address, the user name and password.
This works and the DB shows up correctly.
Then I followed the tutorials here to use create a WCF RIA service:
Add a new project to the solution based on the template WCF RIA Services class library.
Add an ADO.NET entity data model to the WCF RIA Web project and using the wizard connect it to the MySQL database. The generated connection string is
metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=MySql.Data.MySqlClient;provider connection string="server=10.192.xx.yy;User Id=xxxxxxx;database=projet;password=xxxxxxxxxx;Persist Security Info=True".
Add a domain service to the WCF RIA Web project.
This works correctly. The entity diagram shows the three selected tables of the database with all fields.
Then I connected the WCF RIA service to lightswitch following this tutorial here:
In the Lightswitch project, create a new data source and attach it to the WCF RIA service
Add a reference to the WCF RIA Web project and select the required data source objects. This works and the data source objects are correctly imported.
Finally copy the connection string from the WCF RIA Web project file App.config to the file web.config in the server generated project of the Lightswitch project. The line is:
<add name="b70821ef-..." connectionString="metadata=res:///Model.csdl|res:///Model.ssdl|res://*/Model.msl;provider=MySql.Data.MySqlClient;provider connection string="server=10.192.xx.yy;User Id=xxxxxxx;database=projet;password=xxxxxxx;Persist Security Info=True"" providerName="System.Data.EntityClient"/>
The solution can be built without errors. However, when running the Lightswitch application, the details screen for the MySQL table only shows a red cross and indicates that it cannot load the data.
I suspect that the connection string pasted to web.config is wrong.
What is wrong/missing in the above approach or how can I isolate and debug the problem?
Follow this post.
http://lightswitchhelpwebsite.com/Forum/tabid/63/aft/89/Default.aspx
For me it was the solution-> see the last point about config of coonection string
regards