Spring MVC - 为什么我的项目没有运行?

时间:2016-08-30 00:41:20

标签: java eclipse spring maven tomcat

我正在建立一个我工作的另一个项目的新项目,并且还没有能够让它运行起来。

新项目的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>b.c.g</groupId>
    <artifactId>cms-stock</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cms-stockcontrol</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <springframework.version>4.1.6.RELEASE</springframework.version>
        <springsecurity.version>4.0.1.RELEASE</springsecurity.version>
        <hibernate.version>4.3.6.Final</hibernate.version>
        <mysql.connector.version>5.1.38</mysql.connector.version>
        <log4j.version>1.2.17</log4j.version>
        <slf4j.version>1.7.18</slf4j.version>
        <jackson.version>2.7.4</jackson.version>
    </properties>

    <dependencies>

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${springframework.version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${springsecurity.version}</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slf4j.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.3.Final</version>
        </dependency>

        <!-- jsr303 validation -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>

        <!-- JDBC -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.connector.version}</version>
            <!-- <scope>provided</scope> -->
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

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

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.4</version>
        </dependency>

        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.2</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.5.5</version>
        </dependency>

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

        <!-- Templating engine -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring4</artifactId>
            <version>2.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>nz.net.ultraq.thymeleaf</groupId>
            <artifactId>thymeleaf-layout-dialect</artifactId>
            <version>1.3.3</version>
        </dependency>


        <!-- REST -->
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
        </dependency>

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.2</version>
        </dependency>

        <!-- JSON -->
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <warSourceDirectory>src/main/webapp</warSourceDirectory>
                        <warName>hrm</warName>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <finalName>cms-stockcontrol</finalName>
    </build>
</project>

另外,我有一些驻留在src/main/java/b.c.g.configuration的配置文件。我想最重要的是:

AppNameConfiguration

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "b.c.g.s")
public class AppNameConfiguration extends WebMvcConfigurerAdapter {

    private static final String MESSAGE_SOURCE = "i18n/messages";
    private static final String HTML_VIEWS = "/WEB-INF/html/";

    private static final String RESOURCES_HANDLER = "/assets/";
    private static final String RESOURCES_LOCATION = RESOURCES_HANDLER + "**";

    @Autowired
    RoleToUserProfileConverter roleToUserProfileConverter;

    @Bean
    @Description("Thymeleaf template resolver serving HTML 5")
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
        templateResolver.setCacheable(false);
        templateResolver.setTemplateMode("HTML5");
        templateResolver.setCharacterEncoding("UTF-8");
        templateResolver.setPrefix(HTML_VIEWS);
        templateResolver.setSuffix(".html");

        return templateResolver;
    }

    @Bean
    @Description("Thymeleaf template engine with Spring integration")
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.addDialect(new SpringSecurityDialect());
        templateEngine.addDialect(new LayoutDialect(new GroupingStrategy()));
        templateEngine.setTemplateResolver(templateResolver());

        return templateEngine;
    }

    @Bean
    @Description("Thymeleaf view resolver")
    public ViewResolver viewResolver() {

        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(templateEngine());
        viewResolver.setCharacterEncoding("UTF-8");
        viewResolver.setCache(false);
        viewResolver.setOrder(1);

        return viewResolver;
    }

    @Bean(name = "messageSource")
    @Description("Spring message resolver")
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename(MESSAGE_SOURCE);
        messageSource.setFallbackToSystemLocale(false);
        messageSource.setCacheSeconds(0);
        messageSource.setDefaultEncoding("utf-8");
        return messageSource;
    }

    @Bean(name = "localeResolver")
    @Description("Spring locale resolver")
    public LocaleResolver localeResolver() {
        SessionLocaleResolver resolver = new SessionLocaleResolver();
        resolver.setDefaultLocale(new Locale("pt", "BR"));
        return resolver;
    }

    @Bean(name = "multipartResolver")
    public StandardServletMultipartResolver resolver() {
        return new StandardServletMultipartResolver();
    }

    @Bean
    public DataInitializer createDataInitializer() {
        return new DataInitializer();
    }

    @Bean
    public UrlTemplateResolver urlTemplateResolver() {
        return new UrlTemplateResolver();
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(RESOURCES_LOCATION).addResourceLocations(RESOURCES_HANDLER);
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }
}

HibernateConfiguration

@Configuration
@EnableTransactionManagement
@ComponentScan({ "b.c.g.s.configuration" })
@PropertySource(value = "classpath:application.properties")
public class HibernateConfiguration {

    @Autowired
    private Environment environment;

    private static Logger logger = Logger.getLogger(HibernateConfiguration.class);

    @Bean
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setPackagesToScan(new String[] { "br.com.gtludwig.stockcontrol.model" });
        sessionFactory.setHibernateProperties(hibernateProperties());
        return sessionFactory;
    }

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
        dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
        dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
        dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
        return dataSource;
    }

    private Properties hibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
        properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
        properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
        properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
        properties.put("hibernate.connection.driver-class", "com.mysql.jdbc.Driver");
        return properties;        
    }

    @Bean
    @Autowired
    public HibernateTransactionManager transactionManager(SessionFactory s) {
        HibernateTransactionManager txManager = new HibernateTransactionManager();
        txManager.setSessionFactory(s);
        return txManager;
    }
}

src/main/resources上有application.properties

# Connection information
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/databaseName?autoReconnect=true&useSSL=false
jdbc.username=username
jdbc.password=password

# hibernate.X
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update

Eclipse控制台输出以下内容,并且没有任何错误:

Aug 29, 2016 9:26:41 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:cms-stock' did not find a matching property.
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.36
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jun 9 2016 13:55:50 UTC
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.36.0
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            4.4.0-34-generic
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /opt/jdk1.8.0_91/jre
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_91-b14
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /home/gtl/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /home/gtl/dev/apache-tomcat-8.0.36
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.base=/home/gtl/.jrebel
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.env.ide.plugin.version=6.4.8.RELEASE
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.env.ide.version=3.8.1
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.env.ide.product=Spring_Tool_Suite
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.env.ide=Eclipse
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.notification.url=http://localhost:17434
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.workspace.path=/home/gtl/workspace
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Drebel.properties=/home/gtl/.jrebel/jrebel.properties
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentpath:/home/gtl/dev/sts-bundle/sts-3.7.3.RELEASE/plugins/org.zeroturnaround.eclipse.embedder_6.4.8.RELEASE/jr6/jrebel/lib/libjrebel64.so
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/gtl/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/gtl/dev/apache-tomcat-8.0.36
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/gtl/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/home/gtl/dev/apache-tomcat-8.0.36/endorsed
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Aug 29, 2016 9:26:41 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Aug 29, 2016 9:26:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Aug 29, 2016 9:26:41 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 29, 2016 9:26:41 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Aug 29, 2016 9:26:41 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 29, 2016 9:26:41 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1322 ms
Aug 29, 2016 9:26:41 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 29, 2016 9:26:41 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.36
Aug 29, 2016 9:26:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Aug 29, 2016 9:26:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Aug 29, 2016 9:26:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 807 ms

奇怪的是,奇怪的是服务器在不到一秒的时间内启动,所有的mvn依赖都在那里,但是项目没有连接到数据库,也没有创建任何表,也没有触发任何错误。 ..它只是没有开始...

我知道我在这里没有说出一些内容,但我愿意编辑此帖以提供更多信息。请指教。

我在这里看不到什么?

0 个答案:

没有答案