Java webapp,springboot错误

我在我的第一个springboot应用程序上工作 . 我正在处理一些书,我正在一步一步地做每一个想法,当我运行程序时,它是一些我无法解决的错误 . 可能他们很小但我仍在努力解决这个问题,这就是为什么我在这里 .

WebstoreappApplication:

package com.exovsky.webstoreapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WebstoreappApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebstoreappApplication.class, args);
    }

}

HomeController:

package com.exovsky.webstoreapp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String welcome(Model model) {
        model.addAttribute("greeting", "Witaj w sklepie internetowym!");
        model.addAttribute("tagline", "Wyjątkowym i jedynym sklepie 
internetowym");
        return "welcome";
    }

}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.exovsky</groupId>
    <artifactId>webstoreapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>webstoreapp</name>
    <description>webapp project in springboot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.properties:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

错误:2018-02-26 16:55:08.567 INFO 9756 --- [main] cewebstoreapp.WebstoreappApplication:使用PID 9756(C:\ Users \ eXovsky \ Desktop \ Programming \ Projekty \ webstoreapp \ target)在eXovskyPC上启动WebstoreappApplication \ eXovsky在C:\ Users \ eXovsky \ Desktop \ Programming \ Projekty \ webstoreapp)中开始的课程2018-02-26 16:55:08.567 INFO 9756 --- [main] cewebstoreapp.WebstoreappApplication:没有活动的 Profiles 集,掉落返回默认配置文件:默认2018-02-26 16:55:08.568 DEBUG 9756 --- [main] osboot.SpringApplication:加载源类com.exovsky.webstoreapp.WebstoreappApplication 2018-02-26 16:55:08.594 DEBUG 9756 --- [main] osbccConfigFileApplicationListener:已加载的配置文件'file:/ C:/Users/eXovsky/Desktop/Programming/Projekty/webstoreapp/target/classes/application.properties'(classpath:/application.properties)2018- 02-26 16:55:08.594 DEBUG 9756 --- [main] osbccConfigFileApplicationListener:Skipped(空)配置文件'文件:/ C:/ Users / eXovsky / Deskt op / Programming / Projekty / webstoreapp / target / classes / application.properties'(classpath:/application.properties)for profile default 2018-02-26 16:55:08.598 INFO 9756 --- [main] ationConfigEmbeddedWebApplicationContext:刷新组织 . springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6ce86ce1:启动日期[Mon Feb 26 16:55:08 GMT 2018];上下文层次结构2018-02-26 16:55:08.599 DEBUG 9756 --- [main] ationConfigEmbeddedWebApplicationContext:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6ce86ce1的bean工厂:org.springframework.beans.factory.support .DefaultListableBeanFactory @ 44e3a2b2:定义bean [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org . springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,webstoreappApplication];工厂层次结构的根警告:发生了非法的反射访问操作警告:org.springframework.cglib.core.ReflectUtils $ 1的非法反射访问(文件:/ C:/Users/eXovsky/.m2/repository/org/springframework/spring -core / 4.3.14.RELEASE / spring-core-4.3.14.RELEASE.jar)方法java.lang.ClassLoader.defineClass(java.lang.String,byte [],int,int,java.security.ProtectionDomain警告:请考虑向org.springframework.cglib.core.ReflectUtils $ 1的维护者报告此情况警告:使用--illegal-access = warn启用进一步非法反射访问操作的警告警告:所有非法访问操作都将被拒绝未来版本2018-02-26 16:55:09.314 INFO 9756 --- [main] trationDelegate $ BeanPostProcessorChecker:类型为[org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration $的Bean'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' $ EnhancerBySpringCGLIB $$ e6b32090]不是eligibl e由所有BeanPostProcessors处理(例如:不符合自动代理条件)2018-02-26 16:55:09.333 DEBUG 9756 --- [main] ationConfigEmbeddedWebApplicationContext:无法找到名为'messageSource'的MessageSource:默认使用[org.springframework.context.support.DelegatingMessageSource@2d0ecb24] 2018-02-26 16:55:09.333 DEBUG 9756 --- [main] ationConfigEmbeddedWebApplicationContext:无法找到名为'applicationEventMulticaster'的ApplicationEventMulticaster:使用default [org.springframework . context.event.SimpleApplicationEventMulticaster@4d654825] 2018-02-26 16:55:09.522 DEBUG 9756 --- [main] .t.TomcatEmbeddedServletContainerFactory:代码存档:C:\ Users \ eXovsky.m2 \ repository \ org \ springframework \ boot \ spring-boot \ 1.5.10.RELEASE \ spring-boot-1.5.10.RELEASE.jar 2018-02-26 16:55:09.522 DEBUG 9756 --- [main] .t.TomcatEmbeddedServletContainerFactory:代码存档:C:\ Users \ eXovsky.m2 \ repository \ org \ springframework \ boot \ spring-boot \ 1.5.10.RELEASE \ spring-boot-1.5.10.RELEASE.jar 2018- 02-26 16:55:09.523 DEBUG 9756 --- [main] .t.TomcatEmbeddedServletContainerFactory:Document root:C:\ Users \ eXovsky \ Desktop \ Programming \ Projekty \ webstoreapp \ src \ main \ webapp 2018-02-26 16 :55:09.540 INFO 9756 --- [main] sbcetTomcatEmbeddedServletContainer:使用端口初始化的Tomcat:8080(http)2018-02-26 16:55:09.546 INFO 9756 --- [main] o.apache.catalina .core.StandardService:启动服务[Tomcat] 2018-02-26 16:55:09.546 INFO 9756 --- [main] org.apache.catalina.core.StandardEngine:启动Servlet引擎:Apache Tomcat / 8.5.27 2018- 02-26 16:55:09.591 INFO 9756 --- [ost-startStop-1] oaccC [Tomcat] . [localhost] . [/]:初始化Spring embedded WebApplicationContext 2018-02-26 16:55:09.591 INFO 9756 - - [ost-startStop-1] osweb.context.ContextLoader:Root WebApplicationContext:ini tialization在997 ms完成2018-02-26 16:55:09.633 DEBUG 9756 --- [ost-startStop-1] o.s.b.w.s.ServletContextInitializerBeans:添加了现有的Servlet初始化bean'dispatcherServletRegistration'; order = 2147483647,resource = class path resource [org / springframework / boot / autoconfigure / web / DispatcherServletAutoConfiguration $ DispatcherServletRegistrationConfiguration.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbwsServletContextInitializerBeans :为'metricsFilter'创建过滤器初始值设定项; order = -2147483648,resource = class path resource [org / springframework / boot / actuate / autoconfigure / MetricFilterAutoConfiguration.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbwsServletContextInitializerBeans:为bean'characterEncodingFilter'创建了Filter初始值设定项; order = -2147483648,resource = class path resource [org / springframework / boot / autoconfigure / web / HttpEncodingAutoConfiguration.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbwsServletContextInitializerBeans:为bean'hiddenHttpMethodFilter'创建了Filter初始值设定项; order = -10000,resource = class path resource [org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbwsServletContextInitializerBeans:为bean'httpPutFormContentFilter'创建了Filter初始值设定项; order = -9900,resource = class path resource [org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbwsServletContextInitializerBeans:为bean'requestContextFilter'创建了Filter初始值设定项; order = -105,resource = class path resource [org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration $ WebMvcAutoConfigurationAdapter.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbws ServletContextInitializerBeans:为'webRequestLoggingFilter'创建过滤器初始化程序; order = 2147483637,resource = class path resource [org / springframework / boot / actuate / autoconfigure / TraceWebFilterAutoConfiguration.class] 2018-02-26 16:55:09.706 DEBUG 9756 --- [ost-startStop-1] osbwsServletContextInitializerBeans:Created过滤bean'applicationContextIdFilter'的初始值设定项; order = 2147483647,resource = class path resource [org / springframework / boot / actuate / autoconfigure / EndpointWebMvcAutoConfiguration $ ApplicationContextFilterConfiguration.class] 2018-02-26 16:55:09.710 INFO 9756 --- [ost-startStop-1] osbwservlet .ServletRegistrationBean:映射servlet:'dispatcherServlet'到[/] 2018-02-26 16:55:09.712 INFO 9756 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean:映射过滤器:'metricsFilter'到:[/ ] 2018-02-26 16:55:09.712 INFO 9756 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean:映射过滤器:'characterEncodingFilter'为:[/] 2018-02-26 16:55:09.712 INFO 9756 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean:映射过滤器:'hiddenHttpMethodFilter'到:[/] 2018-02-26 16:55:09.713 INFO 9756 --- [ost-startStop-1] osbw servlet.FilterRegistrationBean:映射过滤器:'httpPutFormContentFilter'到:[/] 2018-02-26 16:55:09.713 INFO 9756 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean:映射文件ter:'requestContextFilter'to:[/] 2018-02-26 16:55:09.713 INFO 9756 --- [ost-startStop-1] osbwservlet.FilterRegistrationBean:映射过滤器:'webRequestLoggingFilter'到:[/] 2018- 02-26 16:55:09.713INFO 9756 --- [OST-startStop-1] osbwservlet.FilterRegistrationBean:映射滤波器: 'applicationContextIdFilter' 到:[/ *] 2018年2月26日16:55:09.719 DEBUG 9756 --- [OST-startStop-1 ] osbwfOrderedRequestContextFilter:初始化过滤器'requestContextFilter'2018-02-26 16:55:09.720 DEBUG 9756 --- [ost-startStop-1] osbwfOrderedRequestContextFilter:过滤'requestContextFilter'已成功配置2018-02-26 16:55:09.720 DEBUG 9756 --- [ost-startStop-1] osbwfApplicationContextHeaderFilter:初始化过滤器'applicationContextIdFilter'2018-02-26 16:55:09.720 DEBUG 9756 --- [ost-startStop-1] osbwfApplicationContextHeaderFilter:过滤'applicationContextIdFilter'已配置成功地2018年2月26日16:55:09.720 DEBUG 9756 --- [OST-startStop-1] .sbwfOrderedHttpPutFormContentFilter:初始化滤波器 'httpPutFormContentFilter' 2018年2月26日16:55:09.720 DEBUG 9756 --- [ost- startStop-1] .sbwfOrderedHttpPutFormContentFilter:过滤'httpPutFormContent过滤”成功配置2018年2月26日16:55:09.720 DEBUG 9756 --- [OST-startStop-1] osbwfOrderedHiddenHttpMethodFilter:初始化滤波器 'hiddenHttpMethodFilter' 2018年2月26日16:55:09.721 DEBUG 9756 --- [ ost-startStop-1] osbwfOrderedHiddenHttpMethodFilter:过滤'hiddenHttpMethodFilter'配置成功2018-02-26 16:55:09.721 DEBUG 9756 --- [ost-startStop-1] osbwfOrderedCharacterEncodingFilter:初始化过滤器'characterEncodingFilter'2018-02-26 16:55:09.721 DEBUG 9756 --- [OST-startStop-1] osbwfOrderedCharacterEncodingFilter:过滤器 'characterEncodingFilter' 配置成功2018年2月26日16:55:09.721 DEBUG 9756 --- [OST-startStop-1] osbatrace .WebRequestTraceFilter:初始化过滤器'webRequestLoggingFilter'2018-02-26 16:55:09.721 DEBUG 9756 --- [ost-startStop-1] osbatrace.WebRequestTraceFilter:过滤'webRequestLoggingFilter'配置成功2018-02-26 16:55: 09.721 DEBUG 9756 --- [ost-startStop-1] osbaautoconf igure.MetricsFilter:初始化滤波器 'metricsFilter' 2018年2月26日16:55:09.721 DEBUG 9756 --- [OST-startStop-1] osbaautoconfigure.MetricsFilter:过滤器 'metricsFilter' 成功配置2018年2月26日16点55分:09.728 WARN 9756 --- [main] ationConfigEmbeddedWebApplicationContext:在上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为'org.springframework.boot.autoconfigure.orm.jpa的bean时出错 . HibernateJpaAutoConfiguration':通过构造函数参数0表示的不满意的依赖;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'javax.sql.DataSource'的限定bean可用:预期至少有1个bean可以作为autowire候选者 . 依赖注释:{} 2018-02-26 16:55:09.729 INFO 9756 --- [main] o.apache.catalina.core.StandardService:停止服务[Tomcat] 2018-02-26 16:55:09.737 DEBUG 9756 --- [main] .blClasspathLoggingApplicationListener:应用程序无法以类路径启动:未知2018-02-26 16:55:09.747 DEBUG 9756 --- [main] utoConfigurationReportLoggingInitializer:在此处输入代码2018-02-26 16:55: 09.818 ERROR 9756 --- [main] osbdLoggingFailureAnalysisReporter:APPLICATION FAILED TO START描述:org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration中构造函数的参数0需要一个'javax.sql.DataSource'类型的bean,它可以找不到 . - Bean方法“数据源”不加载,因为@ConditionalOnProperty(spring.datasource.jndi名)没有发现 property “JNDI名” - Bean方法“数据源”不加载,因为@ConditionalOnBean(类型:org.springframework.boot.jta .XADataSourceWrapper; SearchStrategy:all)没有找到任何bean操作:考虑重新访问上面的条件或在配置中定义类型为'javax.sql.DataSource'的bean .

回答(1)

3 years ago

您需要依赖spring-jdbc来自动配置嵌入式数据库here

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.3.13.RELEASE</version>
    <type>jar</type>
</dependency>