I Frühjahr Boot-Anwendung builded, die gut funktioniert, wenn ich es mit mvn spring-boot:run
beginnen, aber versuchen, es java -jar jarName.jar
Ergebnisse in Fehler zu laufen Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'HomeService' available
Frühjahr Boot jar NoSuchBeanDefinitionException
hier ist mein pom.xml mit spring-boot-maven-plugin
wie es hier beschrieben wird https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html und hier Spring-Boot Executable-Jar NoSuchBeanDefinitionException
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/resources/${profileName}</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>target/metamodel</outputDirectory>
<!-- <processors> -->
<!-- <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> -->
<!-- </processors> -->
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.8.RELEASE</version>
<configuration>
<executable>true</executable>
<profiles>
<profile>dev</profile>
<profile>live</profile>
</profiles>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<tasks>
<delete file="src/main/resources/application.properties" />
<copy file="src/main/resources/application-live.properties"
tofile="src/main/resources/application.properties" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<tasks>
<delete file="src/main/resources/application.properties" />
<copy file="src/main/resources/application-dev.properties"
tofile="src/main/resources/application.properties" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
hier App Klasse
@Configuration
@EnableAutoConfiguration
@ComponentScan (basePackages = { "myProject.status" })
public class App {
private static final Logger logger = LogManager.getLogger(App.class);
public static void main(String[] args) throws BeansException, IOException, InterruptedException {
logger.info("APPLICATION STARTED");
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
logger.info(context.getBean(HomeService.class).home());
}
hier ist Homeservice
package myProject.status.service;
@Service
public class HomeService {
public String home() {
return "application works";
}
}
Ich habe auch versucht, eine Bohne in @PostConstruct
Verfahren zu bekommen, wo alles und alle Autowires sollten bereit sein, es funktioniert auch nicht.
Was ist der Unterschied zwischen mvn spring-boot:run
und mvn package
? Wie könnte ich das richtige Glas bauen?
Dank!
Solltest du einfach das Spring Boot Plugin verwenden anstatt das Maven JAR Plugin? – PaulNUK
@PaulNUK selbst wenn ich alle Profile deaktivieren und entfernen Sie diesen Abschnitt von POM eine Spring-Boot-Maven-Plugin-Konfiguration bekomme ich den gleichen Fehler – Slava
Wird Ihre Serviceklasse beim Booten gescannt? – pvpkiran