404 Rest Api with springboot - java

I already have a couple of days in this and although I know they may see the title of the question repeated, the truth is that I have already tried several solutions that have worked for others but not me. The most likely thing is that it's really very silly and I have not seen it yet but I'm on the edge.
This is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>com.paises</groupId>
<artifactId>paises</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>paises</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath />
</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.2-jre</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
This is my class Application
package ar.com.paises;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#SpringBootApplication
#RestController
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
#RequestMapping("/")
String home() {
return "Hello World!";
}
}
And this is my .properties
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url=jdbc:mysql://localhost:3306/test_avantrip?verifyServerCertificate=false&useSSL=false&requireSSL=false
server.port=8083
spring.profiles.active=#spring.profiles.active#
The only message I receive is the following
404 not found api
This is the guide that I was following
Any suggestions?
Update
#RequestMapping(value="/hi", produces= {MediaType.TEXT_PLAIN_VALUE })
public String home() {
return "Hello World!";
}
nothing yet
Update 2
I changed the port, removing it from the .properties and leaving it in 8080 I do not see any change. Additionally here are the messages of the spring boot console when I start it
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
2018-12-05 14:07:29.519 INFO 1844 --- [ main] ar.com.paises.PaisesApplication : Starting PaisesApplication on MIETURAW10 with PID 1844 (D:\Proyectos\avantrip\paises\target\classes started by mietura in D:\Proyectos\avantrip\paises)
2018-12-05 14:07:29.525 INFO 1844 --- [ main] ar.com.paises.PaisesApplication : No active profile set, falling back to default profiles: default
2018-12-05 14:07:30.161 INFO 1844 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2018-12-05 14:07:30.182 INFO 1844 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 repository interfaces.
2018-12-05 14:07:30.734 INFO 1844 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-12-05 14:07:30.764 INFO 1844 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-05 14:07:30.764 INFO 1844 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2018-12-05 14:07:30.772 INFO 1844 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Intel\iCLS Client\;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_161\bin;C:\apache-maven-3.5.3\\bin;C:\apache-maven-3.5.3\\bin;C:\gradle-4.0.1\bin;C:\Users\Etura Maria Ines\AppData\Local\Android\android-sdk\platform-tools;C:\Users\Etura Maria Ines\AppData\Local\Android\android-sdk\tools;C:\Program Files\TortoiseSVN\bin;C:\Program Files\nodejs\;C:\Users\Etura Maria Ines\AppData\Local\Android\android-sdk\;8080;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\apache-ant-1.6.2\bin;C:\Program Files\PowerShell\6.0.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Users\mietura\AppData\Local\Microsoft\WindowsApps;;.]
2018-12-05 14:07:31.138 INFO 1844 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-12-05 14:07:31.138 INFO 1844 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1549 ms
2018-12-05 14:07:31.310 INFO 1844 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-12-05 14:07:31.502 INFO 1844 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-12-05 14:07:31.546 INFO 1844 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-12-05 14:07:31.609 INFO 1844 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
2018-12-05 14:07:31.613 INFO 1844 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-12-05 14:07:31.875 INFO 1844 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2018-12-05 14:07:31.986 INFO 1844 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-12-05 14:07:32.185 INFO 1844 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-12-05 14:07:32.440 INFO 1844 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-12-05 14:07:32.444 INFO 1844 --- [ main] ar.com.paises.PaisesApplication

try removing the property spring.profiles.active=#spring.profiles.active#

Move the #RequestMapping("/") to a controller class, something like :
#RestController
public class Controls {
#RequestMapping("/")
public String home() {
return "Hello World!";
}
}
So your main method would look like :
#SpringBootApplication
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
}

If you take a look at the console logs you won't see that the path "/hi" is not being mapped, which means spring is not able to find your controller bean.
when a path is mapped you should see something like the following in
RequestMappingHandlerMapping : Mapped "{[/hi],methods=[GET]}".
Please move the rest Controller to its own class, it can be in the same File but move it to a new different class something like the following:
package ar.com.paises;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#SpringBootApplication
public class PaisesApplication {
public static void main(String[] args) {
SpringApplication.run(PaisesApplication.class, args);
}
}
#RestController
class HiController {
#RequestMapping("/hi")
String home() {
return "Hello World!";
}
}
Also, make sure that when you're deploying your application a log as the previous one appear.
The way you should call your endpoint according to your port should be:
http://localhost:8083/hi

Related

Not saving to database, Spring Boot, Hibernate, PostgreSQL

Spring Boot 3.0.0 application, after filling out the form and submitting it, the input field is cleared, but saving to the corresponding database table does not occur. There are no errors in the log.
Model
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
#Entity
public class Message {
#Id
#GeneratedValue(strategy= GenerationType.AUTO)
private Integer id;
private String text;
public Message() {
}
public Message(String text) {
this.text = text;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
Repository
import kz.onlineshelter.helppet.model.Message;
import org.springframework.data.repository.CrudRepository;
public interface MessageRepository extends CrudRepository<Message, Long> {}
Controller
import kz.onlineshelter.helppet.model.Message;
import kz.onlineshelter.helppet.repository.MessageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
#Controller
#RequestMapping(method={RequestMethod.POST,RequestMethod.GET})
public class AppController {
private final MessageRepository messageRepository;
#Autowired
public AppController(MessageRepository messageRepository) {
this.messageRepository = messageRepository;
}
#GetMapping("/message")
public String message(Map<String, Object> model) {
Iterable<Message> messages = messageRepository.findAll();
model.put("messages", messages);
return "message";
}
#PostMapping
public String add(#RequestParam String text, Map<String, Object> model) {
Message message = new Message(text);
messageRepository.save(message);
Iterable<Message> messages = messageRepository.findAll();
model.put("messages", messages);
return "message";
}
}
Application
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class HelppetApplication {
public static void main(String[] args) {
SpringApplication.run(HelppetApplication.class, args);
}
}
resources/templates/message.mustache
<html>
<body>
<div>
<form method="post">
<input type="text" name="text" placeholder="Enter your text" /><br>
<button type="submit">Add</button>
</form>
</div>
<div>List of messages</div>
{{#messages}}
<div>
<span>{{text}}</span>
</div>
{{/messages}}
</body>
</html>
application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/***
spring.datasource.username=***
spring.datasource.password=***
spring.jpa.generate-ddl=true
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>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>***</groupId>
<artifactId>helppet</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>***</name>
<description>***</description>
<properties>
<java.version>17</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-mustache</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>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<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-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>
log file
"C:\Program Files\BellSoft\LibericaJDK-17\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar=63010:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.2\bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath "C:\java projects\helppet\target\classes;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\3.0.0\spring-boot-starter-data-jpa-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-aop\3.0.0\spring-boot-starter-aop-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-aop\6.0.2\spring-aop-6.0.2.jar;C:\Users\Admin\.m2\repository\org\aspectj\aspectjweaver\1.9.9.1\aspectjweaver-1.9.9.1.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\3.0.0\spring-boot-starter-jdbc-3.0.0.jar;C:\Users\Admin\.m2\repository\com\zaxxer\HikariCP\5.0.1\HikariCP-5.0.1.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-jdbc\6.0.2\spring-jdbc-6.0.2.jar;C:\Users\Admin\.m2\repository\org\hibernate\orm\hibernate-core\6.1.5.Final\hibernate-core-6.1.5.Final.jar;C:\Users\Admin\.m2\repository\jakarta\persistence\jakarta.persistence-api\3.1.0\jakarta.persistence-api-3.1.0.jar;C:\Users\Admin\.m2\repository\jakarta\transaction\jakarta.transaction-api\2.0.1\jakarta.transaction-api-2.0.1.jar;C:\Users\Admin\.m2\repository\org\jboss\logging\jboss-logging\3.5.0.Final\jboss-logging-3.5.0.Final.jar;C:\Users\Admin\.m2\repository\org\hibernate\common\hibernate-commons-annotations\6.0.2.Final\hibernate-commons-annotations-6.0.2.Final.jar;C:\Users\Admin\.m2\repository\org\jboss\jandex\2.4.2.Final\jandex-2.4.2.Final.jar;C:\Users\Admin\.m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;C:\Users\Admin\.m2\repository\net\bytebuddy\byte-buddy\1.12.19\byte-buddy-1.12.19.jar;C:\Users\Admin\.m2\repository\org\glassfish\jaxb\jaxb-runtime\4.0.1\jaxb-runtime-4.0.1.jar;C:\Users\Admin\.m2\repository\org\glassfish\jaxb\jaxb-core\4.0.1\jaxb-core-4.0.1.jar;C:\Users\Admin\.m2\repository\org\eclipse\angus\angus-activation\1.0.0\angus-activation-1.0.0.jar;C:\Users\Admin\.m2\repository\org\glassfish\jaxb\txw2\4.0.1\txw2-4.0.1.jar;C:\Users\Admin\.m2\repository\com\sun\istack\istack-commons-runtime\4.1.1\istack-commons-runtime-4.1.1.jar;C:\Users\Admin\.m2\repository\jakarta\inject\jakarta.inject-api\2.0.0\jakarta.inject-api-2.0.0.jar;C:\Users\Admin\.m2\repository\org\antlr\antlr4-runtime\4.10.1\antlr4-runtime-4.10.1.jar;C:\Users\Admin\.m2\repository\org\springframework\data\spring-data-jpa\3.0.0\spring-data-jpa-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\data\spring-data-commons\3.0.0\spring-data-commons-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-orm\6.0.2\spring-orm-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-context\6.0.2\spring-context-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-tx\6.0.2\spring-tx-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-beans\6.0.2\spring-beans-6.0.2.jar;C:\Users\Admin\.m2\repository\org\slf4j\slf4j-api\2.0.4\slf4j-api-2.0.4.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-aspects\6.0.2\spring-aspects-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-mustache\3.0.0\spring-boot-starter-mustache-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter\3.0.0\spring-boot-starter-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.0.0\spring-boot-starter-logging-3.0.0.jar;C:\Users\Admin\.m2\repository\ch\qos\logback\logback-classic\1.4.5\logback-classic-1.4.5.jar;C:\Users\Admin\.m2\repository\ch\qos\logback\logback-core\1.4.5\logback-core-1.4.5.jar;C:\Users\Admin\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.19.0\log4j-to-slf4j-2.19.0.jar;C:\Users\Admin\.m2\repository\org\apache\logging\log4j\log4j-api\2.19.0\log4j-api-2.19.0.jar;C:\Users\Admin\.m2\repository\org\slf4j\jul-to-slf4j\2.0.4\jul-to-slf4j-2.0.4.jar;C:\Users\Admin\.m2\repository\org\yaml\snakeyaml\1.33\snakeyaml-1.33.jar;C:\Users\Admin\.m2\repository\com\samskivert\jmustache\1.15\jmustache-1.15.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.0.0\spring-boot-starter-web-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.0.0\spring-boot-starter-json-3.0.0.jar;C:\Users\Admin\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.14.1\jackson-databind-2.14.1.jar;C:\Users\Admin\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.14.1\jackson-annotations-2.14.1.jar;C:\Users\Admin\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.14.1\jackson-core-2.14.1.jar;C:\Users\Admin\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.14.1\jackson-datatype-jdk8-2.14.1.jar;C:\Users\Admin\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.14.1\jackson-datatype-jsr310-2.14.1.jar;C:\Users\Admin\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.14.1\jackson-module-parameter-names-2.14.1.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-web\6.0.2\spring-web-6.0.2.jar;C:\Users\Admin\.m2\repository\io\micrometer\micrometer-observation\1.10.2\micrometer-observation-1.10.2.jar;C:\Users\Admin\.m2\repository\io\micrometer\micrometer-commons\1.10.2\micrometer-commons-1.10.2.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-webmvc\6.0.2\spring-webmvc-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-expression\6.0.2\spring-expression-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-devtools\3.0.0\spring-boot-devtools-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot\3.0.0\spring-boot-3.0.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.0.0\spring-boot-autoconfigure-3.0.0.jar;C:\Users\Admin\.m2\repository\org\postgresql\postgresql\42.5.1\postgresql-42.5.1.jar;C:\Users\Admin\.m2\repository\org\checkerframework\checker-qual\3.5.0\checker-qual-3.5.0.jar;C:\Users\Admin\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.0.0\spring-boot-starter-tomcat-3.0.0.jar;C:\Users\Admin\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\Admin\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.1\tomcat-embed-core-10.1.1.jar;C:\Users\Admin\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.1\tomcat-embed-el-10.1.1.jar;C:\Users\Admin\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.1\tomcat-embed-websocket-10.1.1.jar;C:\Users\Admin\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\4.0.0\jakarta.xml.bind-api-4.0.0.jar;C:\Users\Admin\.m2\repository\jakarta\activation\jakarta.activation-api\2.1.0\jakarta.activation-api-2.1.0.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-core\6.0.2\spring-core-6.0.2.jar;C:\Users\Admin\.m2\repository\org\springframework\spring-jcl\6.0.2\spring-jcl-6.0.2.jar" kz.onlineshelter.helppet.HelppetApplication
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.0)
2022-12-22T10:18:07.901+03:00 INFO 8316 --- [ restartedMain] k.o.***.***Application : Starting ***Application using Java 17.0.4.1 with PID 8316 (*:\***\***\target\classes started by Admin in *:\***\***)
2022-12-22T10:18:07.903+03:00 INFO 8316 --- [ restartedMain] k.o.***.***Application : No active profile set, falling back to 1 default profile: "default"
2022-12-22T10:18:07.944+03:00 INFO 8316 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-12-22T10:18:07.944+03:00 INFO 8316 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-12-22T10:18:08.400+03:00 INFO 8316 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-12-22T10:18:08.435+03:00 INFO 8316 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 30 ms. Found 1 JPA repository interfaces.
2022-12-22T10:18:08.807+03:00 INFO 8316 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-22T10:18:08.815+03:00 INFO 8316 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-22T10:18:08.815+03:00 INFO 8316 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-22T10:18:08.861+03:00 INFO 8316 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-22T10:18:08.861+03:00 INFO 8316 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 917 ms
2022-12-22T10:18:08.950+03:00 INFO 8316 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-12-22T10:18:09.038+03:00 INFO 8316 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection#54ef2cef
2022-12-22T10:18:09.039+03:00 INFO 8316 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-12-22T10:18:09.070+03:00 INFO 8316 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-12-22T10:18:09.110+03:00 INFO 8316 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.5.Final
2022-12-22T10:18:09.232+03:00 WARN 8316 --- [ restartedMain] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
2022-12-22T10:18:09.344+03:00 INFO 8316 --- [ restartedMain] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-12-22T10:18:09.824+03:00 INFO 8316 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-12-22T10:18:09.830+03:00 INFO 8316 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-12-22T10:18:10.004+03:00 WARN 8316 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-12-22T10:18:10.234+03:00 INFO 8316 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-12-22T10:18:10.256+03:00 INFO 8316 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-22T10:18:10.265+03:00 INFO 8316 --- [ restartedMain] k.o.helppet.HelppetApplication : Started HelppetApplication in 2.768 seconds (process running for 4.113)
2022-12-22T10:18:13.951+03:00 INFO 8316 --- [nio-8080-exec-5] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-12-22T10:18:13.952+03:00 INFO 8316 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-12-22T10:18:13.954+03:00 INFO 8316 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
After starting the application, the corresponding table in the database is successfully created
I added an annotation #Repository into Repository, added an annotation #Transactional into Controller in add method, into the signature of the same method added an anotation #ResponseBody but that didn't solve the issue.

I'm making a simple aop example and it does not work

I'm new to java and Spring and I'm currently trying to understand aop. I'm trying to implement very simple code with my custom annotation and #After advice and for some reason it does not work, what I expected was to get on the console 1 and the 2 insted I get only 1 do any of you guys know why?
annotation
package Terative.Services;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.METHOD)
public #interface MyAnnotation {
}
pom
<?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.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</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-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
psvm
package Terative;
import Terative.Services.Simulation_service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
#EnableAspectJAutoProxy
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
Simulation_service mm = new Simulation_service();
mm.metoda();
}
}
aspect
package Terative.Services;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
#RequiredArgsConstructor
#org.springframework.stereotype.Service
#Aspect
#Component
public class Simulation_service {
#Pointcut("#annotation(MyAnnotation)")
public void MyAnnotationMethod() {
}
#MyAnnotation
public void metoda() {
System.out.println("1");
}
#After("MyAnnotationMethod()")
public void metoda2() {
System.out.println("2");
}
}
C:\Users\mtsge\.jdks\azul-13.0.6\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4\lib\idea_rt.jar=51747:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\mtsge\OneDrive\Pulpit\j\demo\target\classes;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.5.2\spring-boot-starter-aop-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter\2.5.2\spring-boot-starter-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot\2.5.2\spring-boot-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.5.2\spring-boot-autoconfigure-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.5.2\spring-boot-starter-logging-2.5.2.jar;C:\Users\mtsge\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\mtsge\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\mtsge\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.14.1\log4j-to-slf4j-2.14.1.jar;C:\Users\mtsge\.m2\repository\org\apache\logging\log4j\log4j-api\2.14.1\log4j-api-2.14.1.jar;C:\Users\mtsge\.m2\repository\org\slf4j\jul-to-slf4j\1.7.31\jul-to-slf4j-1.7.31.jar;C:\Users\mtsge\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\mtsge\.m2\repository\org\yaml\snakeyaml\1.28\snakeyaml-1.28.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-aop\5.3.8\spring-aop-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-beans\5.3.8\spring-beans-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\aspectj\aspectjweaver\1.9.6\aspectjweaver-1.9.6.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.5.2\spring-boot-starter-data-jpa-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.5.2\spring-boot-starter-jdbc-2.5.2.jar;C:\Users\mtsge\.m2\repository\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-jdbc\5.3.8\spring-jdbc-5.3.8.jar;C:\Users\mtsge\.m2\repository\jakarta\transaction\jakarta.transaction-api\1.3.3\jakarta.transaction-api-1.3.3.jar;C:\Users\mtsge\.m2\repository\jakarta\persistence\jakarta.persistence-api\2.2.3\jakarta.persistence-api-2.2.3.jar;C:\Users\mtsge\.m2\repository\org\hibernate\hibernate-core\5.4.32.Final\hibernate-core-5.4.32.Final.jar;C:\Users\mtsge\.m2\repository\org\jboss\logging\jboss-logging\3.4.2.Final\jboss-logging-3.4.2.Final.jar;C:\Users\mtsge\.m2\repository\org\javassist\javassist\3.27.0-GA\javassist-3.27.0-GA.jar;C:\Users\mtsge\.m2\repository\net\bytebuddy\byte-buddy\1.10.22\byte-buddy-1.10.22.jar;C:\Users\mtsge\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\mtsge\.m2\repository\org\jboss\jandex\2.2.3.Final\jandex-2.2.3.Final.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;C:\Users\mtsge\.m2\repository\org\dom4j\dom4j\2.1.3\dom4j-2.1.3.jar;C:\Users\mtsge\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.1.2.Final\hibernate-commons-annotations-5.1.2.Final.jar;C:\Users\mtsge\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.4\jaxb-runtime-2.3.4.jar;C:\Users\mtsge\.m2\repository\org\glassfish\jaxb\txw2\2.3.4\txw2-2.3.4.jar;C:\Users\mtsge\.m2\repository\com\sun\istack\istack-commons-runtime\3.0.12\istack-commons-runtime-3.0.12.jar;C:\Users\mtsge\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\data\spring-data-jpa\2.5.2\spring-data-jpa-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\data\spring-data-commons\2.5.2\spring-data-commons-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-orm\5.3.8\spring-orm-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-context\5.3.8\spring-context-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-tx\5.3.8\spring-tx-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\slf4j\slf4j-api\1.7.31\slf4j-api-1.7.31.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-aspects\5.3.8\spring-aspects-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.5.2\spring-boot-starter-web-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.5.2\spring-boot-starter-json-2.5.2.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.12.3\jackson-databind-2.12.3.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.12.3\jackson-annotations-2.12.3.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.12.3\jackson-core-2.12.3.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.12.3\jackson-datatype-jdk8-2.12.3.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.12.3\jackson-datatype-jsr310-2.12.3.jar;C:\Users\mtsge\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.12.3\jackson-module-parameter-names-2.12.3.jar;C:\Users\mtsge\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.5.2\spring-boot-starter-tomcat-2.5.2.jar;C:\Users\mtsge\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.48\tomcat-embed-core-9.0.48.jar;C:\Users\mtsge\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.48\tomcat-embed-el-9.0.48.jar;C:\Users\mtsge\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.48\tomcat-embed-websocket-9.0.48.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-web\5.3.8\spring-web-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-webmvc\5.3.8\spring-webmvc-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-expression\5.3.8\spring-expression-5.3.8.jar;C:\Users\mtsge\.m2\repository\mysql\mysql-connector-java\8.0.25\mysql-connector-java-8.0.25.jar;C:\Users\mtsge\.m2\repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar;C:\Users\mtsge\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;C:\Users\mtsge\.m2\repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-core\5.3.8\spring-core-5.3.8.jar;C:\Users\mtsge\.m2\repository\org\springframework\spring-jcl\5.3.8\spring-jcl-5.3.8.jar Terative.DemoApplication
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.2)
2021-06-26 16:15:03.432 INFO 8188 --- [ main] Terative.DemoApplication : Starting DemoApplication using Java 13.0.6 on DESKTOP-61G00PJ with PID 8188 (C:\Users\mtsge\OneDrive\Pulpit\j\demo\target\classes started by mtsge in C:\Users\mtsge\OneDrive\Pulpit\j\demo)
2021-06-26 16:15:03.432 INFO 8188 --- [ main] Terative.DemoApplication : No active profile set, falling back to default profiles: default
2021-06-26 16:15:05.764 INFO 8188 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-06-26 16:15:05.800 INFO 8188 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 11 ms. Found 0 JPA repository interfaces.
2021-06-26 16:15:07.758 INFO 8188 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-06-26 16:15:07.779 INFO 8188 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-06-26 16:15:07.779 INFO 8188 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-06-26 16:15:08.007 INFO 8188 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-06-26 16:15:08.007 INFO 8188 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4292 ms
2021-06-26 16:15:08.462 INFO 8188 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-06-26 16:15:08.555 INFO 8188 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-06-26 16:15:08.801 INFO 8188 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-06-26 16:15:08.961 INFO 8188 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-06-26 16:15:09.603 INFO 8188 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-06-26 16:15:09.681 INFO 8188 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2021-06-26 16:15:10.478 INFO 8188 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-06-26 16:15:10.499 INFO 8188 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-06-26 16:15:10.612 WARN 8188 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-06-26 16:15:11.930 INFO 8188 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-06-26 16:15:11.945 INFO 8188 --- [ main] Terative.DemoApplication : Started DemoApplication in 9.53 seconds (JVM running for 10.837)
1
Process finished with exit code -1
Here you create the instance by your self. Spring can not use any aspect on that as it does not belong to the spring context.
Simulation_service mm = new Simulation_service();
mm.metoda();
You need to retrieve the instance from the spring context. Then invoking the method will cause the aspect to execute.
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
Simulation_service mm = context.getBean(Simulation_service.class)
mm.metoda();
}
If everything else is fine tuned it will work. In every case what I describe here is a must in order to move forward.
Turns out advice and custom annotation can't be in the same class which is understandable given the reason for which aop was created, I moved method with custom annotation metoda() to another class and marked it ith #Bean annotation

I am getting NoSuchBeanDefinitionexception while creating a simple Spring Boot project with JpaRepository

I am creating a simple Spring Boot application with JpaRepository, but when I am trying to run my application it gives an error that "NoSuchBeanDefinitionException". I am new to Spring Boot.
I have also tried to annotate my main class with #SpringBootApplication
#EnableJpaRepositories("com.ab.repository") annotations but whenever I am trying to annotate #EnableJpaRepository(), it is showing error in STS that
The type org.springframework.data.repository.config.BootstrapMode cannot be resolved. It is indirectly referenced from required .class files.
Previously I was not using this annotation but I saw in a question that I have to tell my class to enable JPA repository, so I tried this as well, but it is also not working.
My main class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootMain {
public static void main(String[] args) {
SpringApplication.run(SpringBootMain.class, args);
}
}
Controller Class is :
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.ab.model.WebServiceModel;
import com.ab.service.WebSrvService;
#RestController
public class WebServiceController {
#Autowired
private WebSrvService webSrvService;
#PostMapping(value = "/save")
public void saveRecord(#RequestBody WebServiceModel webServiceModel) {
webSrvService.saveRecord(webServiceModel);
}
}
Service class:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ab.model.WebServiceModel;
import com.ab.repository.WebServiceRepository;
#Service
public class WebSrvService {
#Autowired
private WebServiceRepository webServiceRepository;
public void saveRecord(WebServiceModel webServiceModel) {
webServiceRepository.save(webServiceModel);
}
}
Repository Interface:
import org.springframework.data.jpa.repository.JpaRepository;
import com.ab.model.WebServiceModel;
public interface WebServiceRepository extends JpaRepository<WebServiceModel, Integer> {
}
and my pom.xml file is:
<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.ab</groupId>
<artifactId>SpringBootTry</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.10.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.18.RELEASE</version>
</dependency>
</dependencies>
</project>
Please correct me what I am doing wrong, I am Expecting it to run properly but I am getting an error message:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ab.repository.WebServiceRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
After looking through your code that you posted on github i pulled it and rightfully so you have problems with your dependencies. You where missing the spring build plugin that includes all the dependencies in the jar.
Always use the Spring initlizr when starting a new project and it will set up all this for you automatically (unless you have good experience with spring and know what you are doing).
fully working pom.xml
<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.ab</groupId>
<artifactId>SpringBootTry</artifactId>
<version>0.0.1-SNAPSHOT</version>
// latest version of spring as of writing 2.1.7
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
</parent>
// set what version you want of java 1.8, 9, 10, 11, 12?
<properties>
<java.version>11</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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
// You need the spring plugin to bild a fat jar that includes all
// the dependencies. Without this, no dependencies are included in
// the jar and you get NoSuchBeanDefinitionexception
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
you also need to update your application properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
or else you will get a warning when you start your server.
Remove “#Repository”, maybe you can
I created both the folder structure and code like yours.
package com.ab;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootTry1Application {
public static void main(String[] args) {
SpringApplication.run(SpringBootTry1Application.class, args);
}
}
Why you change your main class name?Spring boot automatically create main class for you.
package com.ab.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.ab.model.WebServiceModel;
import com.ab.service.WebService;
#Controller
public class WebServiceController {
#Autowired
private WebService webSrvService;
#PostMapping(value = "/save")
public void saveRecord(#RequestBody WebServiceModel webServiceModel) {
webSrvService.saveRecord(webServiceModel);
}
}
package com.ab.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ab.model.WebServiceModel;
import com.ab.repository.WebServiceRepository;
#Service
public class WebService {
#Autowired
private WebServiceRepository webServiceRepository;
public void saveRecord(WebServiceModel webServiceModel) {
webServiceRepository.save(webServiceModel);
}
}
package com.ab.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.ab.model.WebServiceModel;
public interface WebServiceRepository extends JpaRepository<WebServiceModel,Integer>{
}
## LOGS ##
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-09-01 18:26:27.412 INFO 5522 --- [ main] com.ab.SpringBootTry1Application : Starting SpringBootTry1Application on BGINMAC004.local with PID 5522 (/Users/Dildeep.Singh/Documents/workspace-sts-3.9.9.RELEASE/SpringBootTry-1/target/classes started by Dildeep.Singh in /Users/Dildeep.Singh/Documents/workspace-sts-3.9.9.RELEASE/SpringBootTry-1)
2019-09-01 18:26:27.414 INFO 5522 --- [ main] com.ab.SpringBootTry1Application : No active profile set, falling back to default profiles: default
2019-09-01 18:26:27.992 INFO 5522 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-01 18:26:28.055 INFO 5522 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 57ms. Found 1 repository interfaces.
2019-09-01 18:26:28.354 INFO 5522 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$8d03f4e2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-01 18:26:28.583 INFO 5522 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-09-01 18:26:28.602 INFO 5522 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-01 18:26:28.603 INFO 5522 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.22]
2019-09-01 18:26:28.692 INFO 5522 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-01 18:26:28.692 INFO 5522 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1250 ms
2019-09-01 18:26:28.839 INFO 5522 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-09-01 18:26:28.937 INFO 5522 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-09-01 18:26:28.981 INFO 5522 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-09-01 18:26:29.141 INFO 5522 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-09-01 18:26:29.142 INFO 5522 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-09-01 18:26:29.228 INFO 5522 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-09-01 18:26:29.316 INFO 5522 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-09-01 18:26:29.743 INFO 5522 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#3850e90c'
2019-09-01 18:26:29.746 INFO 5522 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-01 18:26:30.149 INFO 5522 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-01 18:26:30.210 WARN 5522 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-09-01 18:26:30.417 INFO 5522 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-01 18:26:30.420 INFO 5522 --- [ main] com.ab.SpringBootTry1Application : Started SpringBootTry1Application in 18.317 seconds (JVM running for 23.971)
2019-09-01 18:41:39.601 INFO 5522 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-01 18:41:39.602 INFO 5522 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-09-01 18:41:39.615 INFO 5522 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 13 ms
2019-09-01 18:47:48.219 WARN 5522 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=6m18s959ms).
My code compiles fine.
Try to create new spring starter project from STS and do not touch spring boot main class and copy the same folder structure from here.Your code will definitely compiles.

Spring Boot, MySQL, Tomcat can't create intital connections of pool in Eclipse

I have created a webapp using Spring Boot and REST APIs in Eclipse. When I try to run it using Tomcat 8, it gives the error
"o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool."
I tried using the solutions provided but nothing seemed to work, it always gives the same error.
This is my application.properties file -
spring.datasource.url = jdbc:mysql://localhost:3306/dbase?autoReconnect=true&useSSL=false
spring.datasource.username = 1234
spring.datasource.password = 1234
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto = update
and this is the pom.xml file -
<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.springboot</groupId>
<artifactId>springbootrestapi</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springbootrestapiexample Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</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>
<finalName>springbootrestapiexample</finalName>
</build>
</project>
This is the stack trace -
16:33:43.182 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
16:33:43.206 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
16:33:43.207 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Users/Amber%20Bhanarkar/eclipse-workspace/springbootrestapi/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.4.RELEASE)
2019-05-29 16:33:43.767 INFO 13396 --- [ restartedMain] c.s.s.StudentApplication : Starting StudentApplication on LAPTOP-BV6107FE with PID 13396 (started by Amber Bhanarkar in C:\Users\Amber Bhanarkar\eclipse-workspace\springbootrestapi)
2019-05-29 16:33:43.768 INFO 13396 --- [ restartedMain] c.s.s.StudentApplication : No active profile set, falling back to default profiles: default
2019-05-29 16:33:43.892 INFO 13396 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#754391d8: startup date [Wed May 29 16:33:43 IST 2019]; root of context hierarchy
2019-05-29 16:33:49.463 INFO 13396 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-05-29 16:33:49.552 INFO 13396 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-05-29 16:33:49.554 INFO 13396 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.15
2019-05-29 16:33:50.076 INFO 13396 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-05-29 16:33:50.076 INFO 13396 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6188 ms
2019-05-29 16:33:50.354 INFO 13396 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-05-29 16:33:50.359 INFO 13396 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-05-29 16:33:50.360 INFO 13396 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-05-29 16:33:50.360 INFO 13396 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-05-29 16:33:50.360 INFO 13396 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-05-29 16:33:55.529 ERROR 13396 --- [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Here is StudentApplication.java -
package com.springboot.springbootrestapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
#SpringBootApplication
#EnableJpaAuditing
public class StudentApplication {
public static void main(String[] args) {
SpringApplication.run(StudentApplication.class, args);
}
}
You have to change quite few things
1.Goto your mysql installed directory in C drive and find my.ini file.
Change default_authentication_plugin to this
default_authentication_plugin=mysql_native_password
and then goto your MySQL command line client,
After logging in, run this query:
ALTER USER 'yourusername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
then restart the mysql service and run your program.
replace "yourusername" and "yourpassword" with your actual username and password of MySQL.
Goto POM and replace:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
with latest MySQL8 connector
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
i hope it helps :)
These are the things to check
Verify if the database server up and running, and your connection details are working fine in a standalone test.
Grant access if not present, visit :
Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server
Why are you running spring boot within tomcat in the first place and not as a fat jar ?
Secondly, the mysql client JAR should be included in tomcat library
Increase mySQL max connection count, if server is running out of available connections

Basic controller on Spring boot giving 404

I'm trying to create a basic controller on spring boot but I get:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing
this as a fallback.
Fri Dec 14 21:21:36 ART 2018 There was an unexpected error (type=Not
Found, status=404).
No message available
error. I have the controller in a subpackage of the package where the application is located as it should be.
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</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>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
HomeController.java:
package com.example.demo.home;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#RequestMapping("/")
public String home(){
return "home";
}
}
DemoApplication.java:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Console output:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.1.RELEASE)
2018-12-14 21:16:46.179 INFO 5420 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on DESKTOP-BMTCH27 with PID 5420 (C:\Users\Usuario\eclipse-workspace\Project\target\classes started by Usuario in C:\Users\Usuario\eclipse-workspace\Project)
2018-12-14 21:16:46.179 INFO 5420 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2018-12-14 21:16:51.395 INFO 5420 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-12-14 21:16:51.433 INFO 5420 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-14 21:16:51.433 INFO 5420 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2018-12-14 21:16:51.464 INFO 5420 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_192\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_192/bin/server;C:/Program Files/Java/jre1.8.0_192/bin;C:/Program Files/Java/jre1.8.0_192/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;c:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Usuario\AppData\Local\Microsoft\WindowsApps;;C:\Users\Usuario\Desktop;;.]
2018-12-14 21:16:51.871 INFO 5420 --- [ main] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2018-12-14 21:16:51.871 INFO 5420 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-12-14 21:16:51.871 INFO 5420 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5489 ms
2018-12-14 21:16:52.449 INFO 5420 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2018-12-14 21:16:52.959 INFO 5420 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-12-14 21:16:52.975 INFO 5420 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 8.155 seconds (JVM running for 9.247)
2018-12-14 21:17:00.448 INFO 5420 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2018-12-14 21:17:00.448 INFO 5420 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2018-12-14 21:17:00.462 INFO 5420 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 13 ms
Folder strucure
It can be from #Controller annotion. Please change it to #RestController
From spring boot documentation https://spring.io/guides/gs/rest-service/
In Spring’s approach to building RESTful web services, HTTP requests are handled by a controller. These components are easily identified by the #RestController annotation, and the GreetingController below handles GET requests for /greeting by returning a new instance of the Greeting class:
#Controller annotation represents the Spring MVC Controller. If you mark your class with #Controller annotation you have to put #ResponseBody on the handler methods.
On the other side, #RestController annotation is a specialized version of #Controller which adds #Controller and #ResponseBody annotation automatically so there is no need to add #ResponseBody to our handler methods.
#RestController
public class HomeController {
#RequestMapping("/")
public String home(){
return "home";
}
}
or
#Controller
public class HomeController {
#RequestMapping("/")
#ResponseBody
public String home(){
return "home";
}
}
For information : If you do not specify any mapping this method will resolve all the http request i.e. you can send GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE request to the specified url and it will be resolved.
For you case, you change just your controller to look like :
package com.example.demo.home;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#RestController
public class HomeController {
#RequestMapping("/") // Or you can do : #GetMapping("/")
public String home(){
return "home";
}
}
The url:
http://localhost:8080/
For your code/configuration, it will look for the html file under static or webapp folder, meanwhile your home controller should return home.html not home.
Thymeleaf should be included in project's pom.xml as a dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Also the home.html file should be moved from templates to static directory.
For more details have a look at Serving Web Content with Spring MVC.

Categories

Resources