I have read some other threads that tomcat uses only war files for deployment. But then Spring tool suite has internal tomcat server which takes jar for deployment. Correct me if I am wrong.
I did google and find out the steps to deploy war file in tomcat but when followed all the steps and calling rest api says 404 not found.
#RestController
public class TestController {
#RequestMapping("/hello/{name}")
String hello(#PathVariable String name) {
return "Hello, " + name + "!";
}
}
#SpringBootApplication
public class WarDeploymentApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(WarDeploymentApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WarDeploymentApplication.class);
}
}
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 10
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
Edit :: I checked all the tomcat logs, application is deployed and unpacked. spring banner is coming in the logs. no error in the logs.
mapping is there in logs. Only when accesssing rest api using url http://localhost:8081/hello/Admin says 404 not found.
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Thanks
Related
I have a spring boot multi-module project with Gradle. While running the application i am getting the below error:-
Description:
A component required a bean named 'org.springframework.boot.context.internalConfigurationPropertiesBinder' that could not be found.
Action:
Consider defining a bean named 'org.springframework.boot.context.internalConfigurationPropertiesBinder' in your configuration.
The project has a root project which has a subproject 'GetAssociationService'
rootproject - build.gradle
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
bootJar { enabled = false }
jar { enabled = true }
subprojects {
group = 'org.qmetech'
version = '1.0.0'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
}
repositories { mavenCentral ( ) }
ext { set ( 'springCloudVersion' , "Hoxton.SR3" ) }
dependencies {
testImplementation ( 'org.springframework.boot:spring-boot-starter-test' ) {
exclude group: 'org.junit.vintage' , module: 'junit-vintage-engine'
}
}
ext.libraries = [
commonlibraries: [ 'org.springframework.boot:spring-boot-starter:2.2.5.RELEASE' ,
'org.springframework.cloud:spring-cloud-function-context' ,
'org.springframework.cloud:spring-cloud-function-adapter-aws:2.0.1.RELEASE' ,
'com.amazonaws:aws-lambda-java-log4j:1.0.0' ,
'org.springframework.boot:spring-boot-starter-web:2.2.5.RELEASE' ,
'org.springframework.cloud:spring-cloud-starter-function-web:1.0.0.RELEASE' ,
'org.springframework.boot.experimental:spring-boot-thin-layout:1.0.11.RELEASE' ,
'org.springframework.boot:spring-boot-starter-data-mongodb:2.2.5.RELEASE',
'org.springframework.cloud:spring-cloud-function-compiler:2.0.0.RELEASE'] ,
]
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test { useJUnitPlatform ( ) }
ChildProject - build.gradle
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
springBoot {
mainClassName = 'org.qmetech.GetAssociationService'
}
dependencies {
dependencies {
compile libraries.commonlibraries
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
}
UserRepository.java
package org.qmetech.repository;
import org.qmetech.domain.User;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
#Repository
public interface UserRepository extends MongoRepository<User, Integer> { }
AssociationService.java
package org.qmetech.service;
import org.qmetech.domain.User;
import org.qmetech.repository.UserRepository;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.function.Function;
#Component
public class AssociationService implements Function<String, List<User>> {
private final UserRepository userRepository;
public AssociationService(UserRepository userRepository) {
this.userRepository = userRepository;
}
#Override
public List<User> apply(String uppercaseRequest) {
List<User> users = userRepository.findAll();
return users;
}
}
The Complete Code can be found here - https://github.com/iftekharkhan09/Services
Can Anyone please tell me what am I doing wrong?
Thanks!
I also had this problem and in my case, there was the problem in 'org.springframework.boot' version. I changed my version to 2.1.6 Release. Then the problem resolved.
Please verify your pom.xml and make sure you are using the matching version of the Spring boot framework for Spring Cloud.
e.g. For Spring Cloud Greenwich you will need Spring boot 2.1.x
Here is Spring cloud documentation : https://spring.io/projects/spring-cloud
Revisit section : Release Trains
I am creating javafx app with spring boot in background. To do this I used this library: springboot-javafx-support Every time when I start it I get exception "No auto configuration found in META-INF/spring.factories". I have no idea what I am doing wrong. I guess it must be something wrong in my gradle build script.
Below you can find gradle.build file
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'pl.opfol.subiekt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
jar {
enabled = true
}
bootJar {
mainClassName = 'pl.opfol.subiekt.util.MainApp'
}
repositories {
mavenCentral()
maven {
url "https://artifact.aspose.com/repo"
}
maven {
url "https://dl.bintray.com/jerady/maven"
}
}
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('com.h2database:h2:1.4.197')
compile('javax.mail:javax.mail-api:1.6.1')
compile('com.sun.mail:javax.mail:1.6.1')
compile('commons-io:commons-io:2.6')
compile('commons-codec:commons-codec:1.11')
compile('org.apache.commons:commons-collections4:4.1')
compile('org.apache.commons:commons-lang3:3.7')
compile('commons-configuration:commons-configuration:1.10')
compile('com.aspose:aspose-words:17.3.0:jdk16')
compile('com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre9')
compile('javax.annotation:javax.annotation-api:1.3.2')
compile('org.controlsfx:controlsfx:9.0.0')
compile('com.itextpdf:itext7-core:7.1.1')
compile('javax.xml.bind:jaxb-api:2.3.0')
compile('com.jfoenix:jfoenix:9.0.0')
compile('de.roskenet:springboot-javafx-support:2.1.6')
compile('de.jensd:fontawesomefx-controls:9.1.2')
compile('de.jensd:fontawesomefx-commons:9.1.2')
compile('de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2')
compile('de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2')
compile('de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2')
compile('de.jensd:fontawesomefx-octicons:4.3.0-9.1.2')
compile('de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2')
compile('de.jensd:fontawesomefx-materialstackicons:2.1-5-9.1.2')
compile('de.jensd:fontawesomefx-icons525:4.2.0-9.1.2')
compile('de.jensd:fontawesomefx-emojione:3.1.1-9.1.2')
compileOnly ('org.hibernate:hibernate-jpamodelgen:5.2.16.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I had same problem, make sure you run it on JRE 1.8.
As the title says. I'm using IntelliJ IDEA 2017.1.4
My gradle file is following:
group 'org.ks'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.7.RELEASE"
}
}
apply plugin: "org.springframework.boot"
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
But the attempt to use #Autowired annotation causes compilation error
package app;
import org.springframework.beans.factory.annotation.Autowired;
public class AutowiredCls {
#Autowired
private int app_name;
}
Compiler marks import and #Autowired as errors (red underline)
application.yml:
app.name = autowired_sample
What do I do wrong?
Please add below dependencies, you can refer to this for more details
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
}
It doesn't look like your project has any dependencies at all. (I can see that your buildscript has dependencies... but these will not apply to the project sources thamselves.)
Here is a build.gradle file from a project I once generated using https://start.spring.io:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'soffit-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
The project itself (my sources) contains 2 dependencies defined for the compile scope:
org.springframework.boot:spring-boot-starter-cache
org.springframework.boot:spring-boot-starter-web
Both of these are Spring dependencies. I imagine that one (or both) of these give my sources access to the #Autowired annotation... either directly or transitively (probably transitively).
FYI - I 've found the solution. It's best to visit start.spring.io to generate gradle.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-autoconfigure')
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("junit:junit")
}
gradle.properties:
springVersion=1.5.8.RELEASE
When I try to compile/build a Spring Boot project with Spark/Phoenix dependencies, it says there's too many SLF4J's, and when i try to exclude a package, it throws the above error.
How can i get them to work together?
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
//THIS DOESN'T WORK
configurations {
compile.exclude group:'ch.qos.logback'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
/* EXCLUDING HERE ALSO DIDN'T WORK */
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.apache.spark:spark-sql_2.10:1.5.2')
compile('org.apache.spark:spark-core_2.10:1.5.2')
compile('org.apache.phoenix:phoenix-spark:4.7.0-HBase-1.1')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I'm trying to deploy a war generated with springboot in Tomcat, in which I have succeeded previously, but can't figure out what is wrong this time.
The most important code is added:
config/AppConfig
#Configuration
#EnableTransactionManagement
#Component
//#EnableWebMvc
#ComponentScan("com.singleuseapps")
public class AppConfig {
LaptopsApplication
#SpringBootApplication
#ComponentScan(basePackageClasses = {AppConfig.class,LaptopsApplication.class})
public class LaptopsApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(LaptopsApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(LaptopsApplication.class, args);
}
build.gradle
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
apply plugin: 'war'
springBoot{
executable = true
}
jar {
baseName = 'laptops'
}
war {
baseName = 'laptops'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile 'org.hibernate:hibernate-core:5.0.9.Final'
compile("com.h2database:h2")
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'org.javassist:javassist:3.15.0-GA'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'commons-dbcp:commons-dbcp:1.4'
compile('org.springframework.boot:spring-boot-starter-jdbc')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compileOnly "org.projectlombok:lombok:1.16.10"
compile "io.springfox:springfox-swagger2:2.6.0"
compile 'io.springfox:springfox-swagger-ui:2.6.0'
compile 'com.sun.mail:javax.mail'
compile( 'org.springframework.boot:spring-boot-starter-mail')
}
Hope someone gets why I failed.
[edit]
Line in catalina.out
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.singleuseapps.LaptopsApplication]; nested exception is java.io.FileNotFoundException: class path resource [com/singleuseapps/cart/TestMailController.class] cannot be opened because it does not exist
You should:
remove #Component from AppConfig (it's already annotated with #Configuration)
remove .configure method from LaptopsApplication, it's already annotated with #SpringBootApplication and is automatically a configuration class you don't need to add it again
Ensure your controller class is in the package specified by your two #ComponentScan annotations (you probably just need the one on your main app class)