0

Here i am using spring boot, hibernate and sql server database. the problem is, .css is not loading. if i am not integrate with hibernate then .css is loading perfectly. i don't understand why .css is not loading when i am integrate with hibernate ? please give the solution

Project Structure

pom.xml 4.0.0

<groupId>com.example</groupId>
<artifactId>AngularIntegration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

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

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- Optional, for bootstrap -->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.7</version>
    </dependency>
    <!-- Tomcat embedded container-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

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

    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
    </dependency>
</dependencies>

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

SchoolController.java

package com.nd.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SchoolController  {

@RequestMapping("/")
public String welcome(Map<String, Object> model) {
    model.put("message", "All Students");
    return "welcome";
}
}

DBConfiguration.java

package com.nd.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableWebMvc
@ComponentScan
public class DBConfiguration {
@Bean
public HibernateJpaSessionFactoryBean sessionFactory(){
    return new HibernateJpaSessionFactoryBean();
}
}

application.properties

spring.datasource.url=jdbc:jtds:sqlserver://SQLSERVER/abc
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-net.sourceforge.jtds.jdbc.Driver

welcome.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>AngularJS Example</title>  

<link rel="stylesheet" href="/css/school_style.css" type="text/css"/>

</head>
<body>
<div id="main_container">
    <div id="content_container">
        <div id="content">
            <div id="contentborder">
                <div class="content_head">Class Students</div>
                <form method="post" name="frm" id="frm"> 


                    <table align="center" cellpadding="2" cellspacing="2" class="table_border" width="90%">
                        <tr>
                            <br></br>
                            <td class="td_line" align="right" width="50%"><b>Class : </b></td>
                            <td class="td_line" align="left" width="50%">
                            <select size="1" name="cl" id="cl" class="validate[required]">
                                <option value="">Select</option>

                                    <option th:each="clazz : ${allClasses}" value="${clazz.classID}">
                                    <span th:text="${clazz.className}"></span>
                                    </option>

                            </select>
                            </td>
                        </tr>

                        <tr>
                            <td class="td_line" align="right" width="50%"><b>Section :</b></td>
                            <td class="td_line" align="left" width="50%">
                            <select size="1" name="section" id="section" class="validate[required]">
                                    <option value="">Select</option>
                            </select>
                            </td>
                        </tr>

                        <tr>
                            <td class="td_line" align="right" width="50%"><b>Students :</b></td>
                            <td class="td_line" align="left" width="50%">
                            <select size="1" name="term" id="term" onClick="return valid()" class="validate[required]">
                                    <option value="">Select</option>
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center"><br></br>
                                <input type="submit" class="submit" value="Submit"/>
                                <input type="reset" class="submit" value="Reset"/>
                            </td>
                        </tr>
                    </table>

                </form>
            </div>
        </div>
    </div>
</div>

</body>
</html>
Narendra
  • 31
  • 2
  • 4
  • 1
    Remove `@EnableWebMvc` (and you can also remove the `@COmponentScan) from the `DBConfiguration` and restart your application. – M. Deinum Jun 15 '17 at 12:14
  • Remove first `/` here `href="/css/school_style.css"`. Should be `href="css/school_style.css"` – Issam El-atif Jun 15 '17 at 12:30
  • Try this answer: https://stackoverflow.com/questions/41057042/spring-boot-css-showing-up-blank-not-loading-after-trying-everything/41058923#41058923 – Moshe Arad Jun 15 '17 at 20:34

0 Answers0