SHARE
TWEET

Untitled

a guest Oct 4th, 2017 262 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. java -jar myapp.jar
  2.    
  3. 11:41:01.224 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
  4. org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [my.testing.MyAppMain]; nested exception is java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
  5.         at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:482)
  6.         at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184)
  7. ...
  8.    
  9. apply plugin: "java";
  10. apply plugin: "idea";
  11. apply plugin: 'application'
  12. apply plugin: 'eu.appsatori.fatjar'
  13. apply plugin: 'org.springframework.boot'
  14.  
  15. repositories {
  16.     mavenCentral()
  17. }
  18.  
  19. buildscript {
  20.     ext {
  21.         springBootVersion = '1.4.3.RELEASE'
  22.     }
  23.  
  24.     repositories {
  25.         mavenCentral()
  26.         jcenter()
  27.     }
  28.  
  29.     dependencies {
  30.         classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
  31.         classpath "eu.appsatori:gradle-fatjar-plugin:0.3"
  32.     }
  33. }
  34.  
  35. sourceSets {
  36.     main {
  37.         java {
  38.             srcDir 'src/main/java'
  39.         }
  40.  
  41.         resources {
  42.             srcDir 'src/main/resources'
  43.         }
  44.     }
  45.  
  46.     test {
  47.         java {
  48.             srcDir 'src/test/java'
  49.         }
  50.     }
  51. }
  52.  
  53. fatJar {
  54.     manifest {
  55.         attributes("Main-Class": 'my.testing.MyAppMain')
  56.     }
  57.  
  58.     exclude 'META-INF/*.DSA'
  59.     exclude 'META-INF/*.SF'
  60.     exclude 'META-INF/*.RSA'
  61. }
  62.  
  63. dependencies {
  64.     compile 'org.springframework.boot:spring-boot-starter-jdbc'
  65.     runtime 'mysql:mysql-connector-java'
  66.  
  67.     testCompile 'org.springframework.boot:spring-boot-starter-test'
  68.  
  69. }
  70.    
  71. package my.testing;
  72.  
  73. import org.springframework.beans.factory.annotation.Autowired;
  74. import org.springframework.boot.SpringApplication;
  75. import org.springframework.boot.autoconfigure.SpringBootApplication;
  76. import org.springframework.context.ConfigurableApplicationContext;
  77. import org.springframework.jdbc.core.JdbcTemplate;
  78. import org.springframework.stereotype.Component;
  79.  
  80. @SpringBootApplication
  81. public class MyAppMain {
  82.     private ConfigurableApplicationContext springContext;
  83.  
  84.     @Autowired
  85.     private SimpleDao dao;
  86.  
  87.     public static void main(String[] args) throws Exception {
  88.         MyAppMain test = new MyAppMain();
  89.         try {
  90.             test.init();
  91.             test.doWhatYouGotToDo();
  92.         } finally {
  93.             test.stop();
  94.         }
  95.     }
  96.  
  97.     private void doWhatYouGotToDo() {
  98.         System.out.println("Auto-wired dao: " + dao.hashCode());
  99.         System.out.println("Auto-wired jdbcTemplate: " + dao.jdbcTemplate.hashCode());
  100.     }
  101.  
  102.     private void init() throws Exception {
  103.         springContext = SpringApplication.run(MyAppMain.class);
  104.         springContext.getAutowireCapableBeanFactory().autowireBean(this);
  105.     }
  106.  
  107.     private void stop() throws Exception {
  108.         springContext.close();
  109.     }
  110. }
  111.  
  112. @Component
  113. class SimpleDao {
  114.  
  115.     @Autowired
  116.     JdbcTemplate jdbcTemplate;
  117. }
  118.    
  119. spring.datasource.driver-class-name = com.mysql.jdbc.Driver
  120. spring.datasource.url = jdbc:mysql://localhost:3306/some_db?useSSL=false&serverTimezone=UTC
  121. spring.datasource.username = some_user
  122. spring.datasource.password = some_pass
  123.    
  124. gradle clean build
  125. gradle bootRepackage
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top