开发者社区 问答 正文

搭建SSM启动报错,启动后又不影响正常使用?报错

报错内容如下:

[org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.username' in [localProperties]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Found key 'jdbc.username' in [localProperties] with type [String] and value 'root'
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [environmentProperties]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [servletConfigInitParams]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [servletContextInitParams]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [jndiProperties]
  [org.springframework.jndi.JndiTemplate] - Looking up JNDI object with name [java:comp/env/jdbc.password]
  [org.springframework.jndi.JndiLocatorDelegate] - Converted JNDI name [java:comp/env/jdbc.password] not found - trying original name [jdbc.password]. javax.naming.NameNotFoundException: Name [jdbc.password] is not bound in this Context. Unable to find [jdbc.password].
  [org.springframework.jndi.JndiTemplate] - Looking up JNDI object with name [jdbc.password]
  [org.springframework.jndi.JndiPropertySource] - JNDI lookup for name [jdbc.password] threw NamingException with message: Name [jdbc.password] is not bound in this Context. Unable to find [jdbc.password].. Returning null.
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [systemProperties]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [systemEnvironment]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Could not find key 'jdbc.password' in any property source. Returning [null]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'jdbc.password' in [localProperties]
  [org.springframework.core.env.PropertySourcesPropertyResolver] - Found key 'jdbc.password' in [localProperties] with type [String] and value 'an123456'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Eagerly caching bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' to allow for resolving potential circular references
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Finished creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' to allow for resolving potential circular references
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating shared instance of singleton bean 'org.springframework.aop.config.internalAutoProxyCreator'
  [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Creating instance of bean 'org.springframework.aop.config.internalAutoProxyCreator'

配置文件的结构如下:

spring-jdbc.xml的配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">


	<!-- <context:component-scan base-package="com.springmvc.test" /> -->
	<context:component-scan base-package="com.springmvc" />

	<!-- 配置整合mybatis过程 -->
	<!-- 1.配置数据库相关参数properties的属性:${url} -->
	<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />

	<!-- 2.数据库连接池 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	<!-- 3.配置SqlSessionFactory对象 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 注入数据库连接池 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
		<property name="configLocation" value="classpath:mybatis-config.xml" />
		<!-- 扫描entity包 使用别名 -->
		<!-- <property name="typeAliasesPackage" value="com.springmvc.test.entity" /> -->
		<property name="typeAliasesPackage" value="com.springmvc.entity" />
		<!-- 扫描sql配置文件:mapper需要的xml文件 -->
		<!-- <property name="mapperLocations" value="classpath:com/springmvc/test/mapper/*.xml" /> -->
		<property name="mapperLocations" value="classpath:com/springmvc/mapper/*/*.xml" />
	</bean>

	<!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 注入sqlSessionFactory -->
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
		<!-- 给出需要扫描Dao接口包 -->
		<!-- <property name="basePackage" value="com.springmvc.test.dao.impl" /> -->
		<property name="basePackage" value="com.springmvc.*.dao.impl" />
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 注入数据库连接池 -->
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 配置基于注解的声明式事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />

</beans>

jdbc.properties的配置文件如下:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=UTF8
jdbc.username=root
jdbc.password=an123456

大佬们请帮忙解答。

展开
收起
爱吃鱼的程序员 2020-06-06 21:16:40 569 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p><a rel="nofollow">https://blog.csdn.net/superdog007/article/details/48022983</a></p>
    

     

    看下这里

                            其实这个不影响的,一般默认log级别为 info 就看不到了
                        
    
                            property-placeholder中添加local-override=true
    

    这个试了吗?

                            之前试过了,还是报错
    
    2020-06-06 21:16:54
    赞同 展开评论