Java Maven依赖项不适用于springMVC项目

Java Maven依赖项不适用于springMVC项目,java,spring,maven,spring-mvc,spring-boot,Java,Spring,Maven,Spring Mvc,Spring Boot,我已经创建了一个简单的helloWorld maven依赖项,并将其放在我的springmvc项目中pom.xml,但在部署它的showing bean创建时,该helloWorld:not是一个合格的bean 任何帮助都将不胜感激。非常感谢。 下面是我的依赖项目的样子 My Application.java 包com.test @Configuration @EnableAutoConfiguration @ComponentScan({"com.test"}) @EnableTran

我已经创建了一个简单的helloWorld maven依赖项,并将其放在我的springmvc项目中
pom.xml
,但在部署它的showing bean创建时,该
helloWorld:not
是一个合格的bean

任何帮助都将不胜感激。非常感谢。 下面是我的依赖项目的样子 My Application.java 包com.test

    @Configuration
@EnableAutoConfiguration
@ComponentScan({"com.test"})
@EnableTransactionManagement
public class Application {
       public static void main(String[] args) {
            System.out.println("hai");
            SpringApplication app = new SpringApplication(Application.class);
            app.run(args);
        }
}
My Controller

    package com.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


import test.Application;
import test.controller.Check;

@RestController
@RequestMapping("/Rest")
public class Controller {

    @Autowired
    Check check; // this is the bean from that dependency

    @RequestMapping(value="/logs",method=RequestMethod.GET)
    public String logs(){

        return "I am the controler";
    }
}
我的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>waffleTalentpool</groupId>
<artifactId>waffleTalentpool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
<properties>
    <java.version>1.8</java.version>
</properties>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.1.RELEASE</version>
</parent>
<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>server-api</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>com.github.dblock.waffle</groupId>
        <artifactId>waffle-jna</artifactId>
        <version>1.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.github.dblock.waffle</groupId>
        <artifactId>waffle-tomcat8</artifactId>
        <version>1.7.3</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>logback-classic</artifactId>
                <groupId>ch.qos.logback</groupId>
            </exclusion>
            <exclusion>
                <artifactId>log4j-over-slf4j</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    **<dependency>
        <groupId>test</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>** // This is my maven dependency for standalone java application

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.10-FINAL</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.10-FINAL</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.1</version>
    </dependency>


</dependencies>
<repositories>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

4.0.0
华夫饼干池

您的项目结构不符合maven标准。我更新了结构并上传到这里。请尝试让我知道这是否有效


提供更多详细信息-日志、配置等。问题很可能不在项目依赖关系中,而是在缺少Bean感谢您的回复。我已经在我的问题中添加了我的代码。上面的答案是关于spring boot应用程序的。您需要对Application.java进行一些小的更改,以使war应用程序正常工作。更改为向@ComponentScan({“com.test”,“test”})注释添加额外的包测试
    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>waffleTalentpool</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>TP</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>
      <param-name>contextClass</param-name>
      <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </init-param>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>com.test.Application</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>TP</servlet-name>
    <url-pattern>/tp/*</url-pattern>
  </servlet-mapping>
</web-app>