1

I have read various SO question, spring tutorials and looked at different example projects, but i still do not get it. Among others were these: unable to connect spring with mysql http://www.codejava.net/frameworks/spring/spring-mvc-with-jdbctemplate-example

My goal is to get a GRADLE spring boot/web application that connects to my MySql database.

My problem is there are many different ways to configure your project.

I would like to use as few XML as possible.

So my question is, whether it is possible to achieve my goal without having a single XML file and if so - how?

Or if i need an XML file(it should then be the pom.xml I think). I would like an explanation why I need it and what the file does in general.

Please NOTE: I have about zero knowledge how to configure spring, mysql, hibernate. So also things that may be straightforward for you, could be unclear to me. So I would really appreciate explanantions.

EDIT2:

I got an sample application running using Spring Initializer

BUT, this sample application uses Maven - to be exactly it uses this pom.xml:

 <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.test</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>demo.DemoApplication</start-class>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Is there an eaasy way I can replace this code with gradle or some kind of tutorial that tells me how to replace this code with the correct gradle file?

3
  • 1
    I have about zero knowledge about spring, mysql, hibernate. so what knowledge do you have so far? and why do you want to build spring application then? Commented Apr 14, 2015 at 20:30
  • pom.xml is used for Maven to build your project. Completely different tool. You may have a better time with SO if you give things a try first, look to see whether anyone else did it, and if not, post your specific question. Not going to sugar coat it - learning all these areas is very time-consuming. You can teach yourself, but it would be much faster and less painful to have someone show you some basics. Commented Apr 14, 2015 at 22:07
  • okay maybe i didn´t write it correctly - i have zero knowledge how to configure a project. I have worked in a few springboot projects with different databases, but I always got the completely configured project Commented Apr 15, 2015 at 12:22

1 Answer 1

1

The simplest way may be for you to download a "bootstrapped" project using the Spring Initializr. You can select the dependencies that you require and the build system, and it will generate your project for you.

For Spring Boot to connect to your MySQL instance, it should be sufficient to just have the following properties in your application.properties file:

spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=user
spring.datasource.password=password

See the Spring Boot Reference for Working with SQL databases for more information.

Sign up to request clarification or add additional context in comments.

2 Comments

I´ll try this as soon as i come come. If this works it is exactly what i want! Thank you
Just select Gradle instead of Maven when you create your app using the initializer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.