Spring boot MVC template - tomcat7 giving 404 error - java

if i call the default url for my tomcat server, i will see an error 404. The program is running without any problems, but perhaps the restcontroller is disabled (i don't known, normally not). There are no erros in the log. The start page is a html-format. I set the default path (see below).
Im using Spring Boot and tomcat7.
The requested resource (/dashboard/) is not available.
Spring Boot path src\main\resources\templates\index.html
Index.html path in war: ..\tomcat7\webapps\dashboard\WEB-INF\classes\templates\index.html
Main
#Configuration
#EnableAutoConfiguration
#ComponentScan(basePackages = "com.###.dashboard")
#EnableJpaRepositories
#EntityScan(basePackages = "com.###.dashboard.domain")
public class Dashboard extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(new Object[] {Dashboard.class, DashboardController.class}, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Dashboard.class);
}
}
RestController
#RestController
public class DashboardController {
/**
*...
*/
#RequestMapping("/")
public String setPage(Model model) {
// ...
return "index";
}
}
pom
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.###.dashboard</groupId>
<artifactId>Dashboard</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Dashboard</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mobile</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<start-class>com.###.dashboard.main.Dashboard</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
tomcat7 server
2014-12-05 13:31:46.836 INFO 28052 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],param
s=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.###.dashboard.domain.DashboardController.setPage(org.springframework.ui.Model)
Thank you

try to put templates in src/main/resources/templates (it's another default path for spring boot)
it works for me and resources/templates sounds better than resources/resources :)

Try annotating your controller as #Controller and give '/dashboard' default request mapping to the controller so that the dashboard controller can answer to the requests with uri starting as '/dashboard'
#Controller
#RequestMapping("/dashboard")
public class DashboardController
Use debug points to see whether the request has fallen thourgh your controller pipeline, white page might be related to an empty template

It means your spring container is not able to find the default page. Just add your home page into the src or make a proper redirection of the home page. For the testing purpose you can use the complete mapping on the web where you have put the home page.

With below changes it worked.
I commented out spring-boot-starter-thymeleaf because it was asking to put some templates to /templates folder.
After that i added #ResponseBody to RequestMapping to return String.
#RequestMapping("/")
public #ResponseBody String setPage(Model model) {
return "index";
}
So maybe you have problem with spring-boot-starter-thymeleaf
Note: I started the tomcat using spring-boot-maven-plugin plugin in your pom with command line mvn spring-boot:run

Here's quite so many get errors while working with Tomcat7 without MAVEN like adding hibernate validator and hibernate dependencies in spring notice one thing update your eclipse. And shift to Tomcat 8 it is set up with API-3.0 so every hibernate component works with it. Even some error doubts just free to ask me.
#navajavadevolper

Related

Simple Spring Boot Project is giving 404 Error

I am learning Spring Boot but I am not able to execute the basic "Hello World" program. I have built the basic project using https://start.spring.io/ and updated the code as per below code snippets:
Spring Boot Main Class:
package com.rohit.springboot.practice.selfspringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
#ComponentScan(basePackages = "com.rohit.springboot.practice.selfspringboot")
public class SelfSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SelfSpringBootApplication.class, args);
}
}
Controller Class:
package com.rohit.springboot.practice.selfspringboot;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class ThisWorldSpringContainer {
#RequestMapping(method = RequestMethod.GET, value = "/hello-world")
public String getWelcome() {
return "Hello World";
}
}
POM.xml file:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rohit.springboot.practice</groupId>
<artifactId>self-spring-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>self-spring-boot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</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>
Error:
Message: The requested resource [/hello-world] is not available
I know this question has been asked by multiple people but i have gone through those answers and tried those given answers but didn't work.
Technologies used are Java 8, Tomcat 9, Spring Boot 2.6.6 etc.
Kindly help.
Since you don't have the Tomcat dependency, I'm implying that you want your application to run in a standalone Tomcat instance. Also, given your comment, I believe you're working on either Eclipse or Spring Tools Suite (Which is the same, really).
With that, it seems your problem is the lack of a packaging method. Tomcat needs the code its going to run in a package. This package is a zip-like file with .war extension. Maven, the program that handles the dependencies of your project according to the pom.xml file, can package it in either war of jar format. Since you are running it in an external Tomcat, you want the war extension. So please, add the following line to your pom.xml file. It has to be in the same level as <name>:
<packaging>war</packaging>
Then, update your project (Alt + F5, check your project and hit OK) then try running your project again. You should see an stylish "SPRING" output in your console.
Now, since you are running this externally, you need to specify the name of the project, so you should call your endpoint with
http://localhost:8080/<your_project_name_here>/hello-world
I advise you to check this new change in Spring Boot 2.6 :
PathPattern Based Path Matching Strategy for Spring MVC
In this release, the default strategy for matching request paths against registered Spring MVC handler mappings has changed from AntPathMatcher to PathPatternParser.
If you need to switch the default strategy back to AntPathMatcher, you can set the property spring.mvc.pathmatch.matching-strategy to ant-path-matcher as in the line below to add in the file application.properties :
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
I encountered the same issue of HTTP 404 error when upgrading to Spring Boot 2.6 and adding this property solved my problem and should solve yours.
I have modified your code as below:
#RequestMapping
#RestController
public class ThisWorldSpringContainer {
#GetMapping(value = "/hello-world")
public String getWelcome() {
return "Hello World";
}
}
I thinking you are missing
#Requestmapping
in classlevel

Basic spring boot app not working, showing: Failed to refresh live data from process xxxx

I am beginner for spring boot. I initialized a new project and tried to run it but it does not work successfully. WHen I run this as spring boot application, it starts execution. In bottom compiler/status bar, it shows processing and retrying. it goes upto 10 times and throw the following error:
Failed to refresh live data from process xxxx
More detail here
TanmayTestApplication.java
package com.example.tanmay_test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TanmayTestApplication {
public static void main(String[] args) {
SpringApplication.run(TanmayTestApplication.class, args);
}
}
DemoControler.java
package com.example.cntr;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
#RestController
public class DemoControler {
#RequestMapping(path = "/index")
public String index() {
return "By Tanmay!";
}
}
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>tanmay_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>tanmay_test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I had the same problem in STS, and tried different things to resolve it. The following dependency for spring actuator makes that problem disappear, but however the main point of spring actuator provides more features than this. To learn more, click https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html
The dependency should be added to your pom.xml file
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
I have faced the same problem but managed to solve it.
The controller class has to be in the "child package" relative to the TestApplication class.
In your case, your TanmayTestApplication class is in the package com.example.tanmay_test. Therefore, your DemoControler class must be inside the package com.example.tanmay_test.xxx.
**Note that xxx can be anything but extends from package com.example.tanmay_test. For example, package com.example.tanmay_test.web.
Hope this helps!
Add this line in your file application.properties (src/main/resources):
spring.devtools.livereload.enabled=true
Live data is collected with the help of Spring Actuator.
You need to include the following dependency in your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
See https://github.com/spring-projects/sts4/wiki/Live-Application-Information#application-requirements-for-spring-boot-projects for reference.
I was also facing same issue after adding Spring Actuator dependency, it resolved.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
after adding this in POM.xml, do maven build and run again.
It is simply saying that you didn't enable LiveReload.
This is non other then the Data Source error
To resolves this I disabled the auto-configuration of the DataSource. And, this will not affect auto-configuring any other beans.
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
I'm using VS Code and the thing that worked for me was adding a dev tool dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
Also, add spring.devtools.livereload.enabled=true in application.properties file so that server knows that it has to reload every time a change is made.
Thanks for this one.

[Solved]Request Mapping returns 404 instead of the mapped String after creating a basic example from spring.start.io

Solution: rename package Controller to myrest.controller , has to be a subpackage of the main package(the one that contains the main method)
I've already been on the following topics but none seemed to worked for me:
RequestMapping leads to 404 Error , added the regex ( /app/** to Rest Controller and **/api to the Method) but still won't map it.
Spring #RequestMapping, 404 error , added <packaging>jar</packaging>
to my pom.xml , although i can't find the path to change it (i doubt that the issue might be there, i'm not sure though).
Request Mapping returning error 404 , i visit the correct endpoint which is localhost:8080/api (port is not in use), i also tried it with another port number.
Spring RequestMapping 404 error , we might have the same issue here, i don't see why i should change the mapping, haven't changed anything on default directories or files.
This is not the first time i'm making a Springboot application
My 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>myrest</groupId>
<artifactId>remoteapi</artifactId>
<version>0.0.1</version>
<name>remoteapi</name>
<description>Rest Mobile Dev ICSD Api</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
My RestController class
package Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class MainController {
#RequestMapping(value="/api")
public String test()
{
return "Hello World";
}
}
This is my directory, the MainController class is inside Controller package
The URL i'm accessing it from is localhost:8080/api
Important Note: if i run the exact method with the exact mapping on an older project, it runs perfectly.
My Comments: This is pretty odd , since i've never changed anything on configurations, probably i missed something when i created the project? I Still haven't figured what that might be.
Edit: Added the directory, and the that location i'm trying to access it
I renamed the Controller package to myrest.controller ,
has to be a subpackage of the main package!
As I remember, SpringBoot only scan packages which have the same prefix with Application class (in your case: myrest).
If you want spring boot scan another package, you should define them through annotation: #ComponentScan("package.hear")

Initial springboot starter project setup - facing issue

I am trying to make a simple spring web application using Spring boot starter package provided. I am able to display 'Hello World' into console, but when I am trying to open localhost:(port), it is showing me . I am using JRE 8. Tried using JDK8 but also gives me same error. Do we have to use JDK or JRE ?
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 02 21:58:01 MDT 2018
There was an unexpected error (type=Not Found, status=404).
No message available
I am trying to resolve this issue from from last 2 days but I am stuck at this!.
Please find below images and code which I have in my system.
Project Structure
Spring Starter Project Application .java
package com.gami.mvc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
#SpringBootApplication
public class SpringStarterProjectApplication extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringStarterProjectApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringStarterProjectApplication.class, args);
System.out.println("Hello World");
}
}
Pom.Xml file
<?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>com.gami.mvc</groupId>
<artifactId>springStarterProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springStarterProject</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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>
<!-- This is a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Tomcat embedded container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Optional, test for static content, bootstrap CSS -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Contoller. java
package com.gami.mvc;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
public class WelcomeController {
// inject via application.properties
#Value("${welcome.message:test}")
private String message = "Hello World";
#RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("message", this.message);
return "welcome";
}
}
Application.properties
server.port=8456
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
welcome.message: Hello Gami
Error receiving when running the application
Error Message
Please any help is really appreciate!
Thank you
Hardik Gami
Console Image
Console msg after hitting to local host
Java Build Path Error
Java Build Path - Eclipse Java Build Path of Project
Spring will search for classes annotated with #Controller on the configured search path, without this annotation spring won't pick up your controller class.
#Controller
public class WelcomeController { ... }
Need to annotate your class with #RestController, or this will search for the welcome.jsp
JRE will not have the Compiler. Use JDK, which will have development tools like javac, javap etc.

The type org.springframework.data.repository.Repository cannot be resolved. It is indirectly referenced from required .class files

I am new for spring Boot, I got this problem when I follow the Spring Guide-Accessing data with MySQL
I got an Error in my STS IDE, I don't know what's the hell happening.
In the src/main/java/UserRepository.java
package hello;
import org.springframework.data.repository.CrudRepository;
import hello.User;
public interface UserRepository extends CrudRepository<User, Long> {
}
STS does warn me about this mistake, I ignore it until I run Cmd: mvn spring-boot
so I am back to check the warning, it is:
The type org.springframework.data.repository.Repository cannot be
resolved. It is indirectly referenced from required .class files
Thanks very much for helping me!
I bulid the project using Maven as recommended,the Pom.xml is:
<?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.springframework</groupId>
<artifactId>gs-mysql-data</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Use MySQL Connector-J -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Apply some spring boot standards to the code
Keep your boot application on top of the package, in your case your BootApplication should be in hello package. Like shown in below
#SpringBootApplication
public class BootApplication extends SpringBootServletInitializer {
public static void main(String args[]) {
SpringApplication.run(BootApplication.class, args);
}
}
Now keep your repository inside the sub-package of hello. In your case it should be in hello.repository
Now try to run with BootApplication.
Buddy,It doesn't work anyway.This Exception is caused by CrudRepository.The eclipse can't resolve this class.My project is very simple,I get this project from spring website.its guide--Accessing data with MySQL
And now my project is completely same as [gs-accessing-data-mysql-complete]
The Spring official Website think it is successful project,and let the trainer to check [gs-accessing-data-mysql-initial] against [gs-accessing-data-mysql-complete]
.Howerver,even the later can't be build successfully.My project structure:
src
+main
+java
+hello
--Application.java
--MainController.java
--User.java
--UserRepository.java
and the log info ,I had better show you about the digest:
1.[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:run (default-cli) on project gs-mysql-data: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'mainController' defined in file [D:\workbunch\Spring Workbunch\gs-accessing-data-mysql-initial\target\classes\hello\MainController.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [hello.MainController] from ClassLoader [java.net.URLClassLoader#6424f2f4]: org/springframework/data/repository/CrudRepository: org.springframework.data.repository.CrudRepository -> [Help 1]

Categories