Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAkash Kashyap
5,635 PointsSpring MVC - unable to deploy war in AWS
I have built a sample spring app following the tutorial. Everything works as expected when i run the application locally in tomcat but when i deploy the application on AWS ...it fails
here is AppConfig.java class
package com.akash.lab2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* Created by akash on 08/11/16.
*/
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class AppConfig extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
return application.sources(applicationClass);
}
public static void main(String args[]){
SpringApplication.run(applicationClass,args);
}
private static Class<AppConfig> applicationClass = AppConfig.class;
}
Dataconfig.java
package com.akash.lab2.config;
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import javax.sql.DataSource;
/**
* Created by akash on 11/12/16.
*/
@Configuration
@PropertySource("classpath:app.properties")
public class DataConfig {
@Autowired
private Environment env;
@Bean
public LocalSessionFactoryBean sessionFactory(){
Resource config = new ClassPathResource("hibernate.cfg.xml");
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setConfigLocation(config);
sessionFactory.setPackagesToScan(env.getProperty("lab2.entity.package"));
sessionFactory.setDataSource(dataSource());
return sessionFactory;
}
@Bean
public DataSource dataSource() {
BasicDataSource ds = new BasicDataSource();
//Driver class name
ds.setDriverClassName(env.getProperty("lab2.db.driver"));
//Set the Url
ds.setUrl(env.getProperty("lab2.db.url"));
//set username
ds.setUsername(env.getProperty("lab2.db.username"));
//set password
ds.setPassword(env.getProperty("lab2.db.password"));
return ds;
}
}
gradle build file
group 'com.akash'
version '1.0-SNAPSHOT'
buildscript{
repositories{
mavenCentral()
}
dependencies{
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
jar{
baseName = 'test'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework:spring-orm:4.3.3.RELEASE'
compile 'org.hibernate:hibernate-core:5.2.4.Final'
compile 'org.apache.tomcat:tomcat-dbcp:9.0.0.M11'
compile 'mysql:mysql-connector-java:6.0.5'
}
1 Answer
Corey Johnson
Courses Plus Student 10,192 PointsHello Akash,
Can you provide more info on the failure? What errors are you seeing?
Thank you.
Akash Kashyap
5,635 PointsAkash Kashyap
5,635 Pointsfigured it out.....its was typo in connection URL in app. properties file
Thanks Corey.....the deployment status in Elastic bean stalk was green so i never looked in deployment logs until you asked more info about errors