0
面對異常而運行的應用程序DROPWIZARDorg.apache.ibatis.binding.BindingException:無效界語句(未找到):db.UserMapper.xxx
ERROR [2016年12月30日04:36:34735] io.dropwizard.jersey.errors.LoggingExceptionMapper:處理請求時出錯:6813de3aa499e307 ! org.apache.ibatis.binding.BindingException:綁定語句無效(未找到):db.UserMapper。
@Path("/user/{username}")
public class ExampleResource {
private final SqlSessionFactory sessionFactory;
public ExampleResource(SqlSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@GET
public User getUser(@PathParam("username") String username) {
try (SqlSession session = sessionFactory.openSession())
{
UserMapper users = session.getMapper(UserMapper.class);
//session.getConfiguration().addMapper(UserMapper.class);
//UserMapper users = session.getMapper(UserMapper.class);
return users.findByUsername(username);
}
}
}
UserMapper.xml
<mapper namespace="db.UserMapper" class="db.UserMapper">
<select id="findByUsername" resultType="User">
<![CDATA[
select username,email
from user
where username = #{username}
]]>
</select>
<resultMap id="User" type="core.User">
<id column="username" property="username" />
<result column="email" property="email" />
</resultMap>
<insert id="addUser">
<![CDATA[
insert into user (username, email)
values (#{User.username}, #{User.email})
]]>
</insert>
user mapper.java
public interface UserMapper {
User findByUsername(@Param("username") String username);
void addUser(@Param("user") User user);
}
ConfigurationClass:
@Valid
@NotNull
private DataSourceFactory datasourceFactory = new DataSourceFactory();
@JsonProperty("database")
public DataSourceFactory getDataSourceFactory() {
return this.datasourceFactory;
}
public void setDatabase(DataSourceFactory database) {
this.datasourceFactory = database;
}
你在哪裏保存了xml文件?你在使用maven嗎?也發佈配置文件,瞭解你是否在添加mapp * xml文件 –
項目中的xml文件是我們保存的.yml文件。我使用這個Mapper.xml文件只映射界面,沒有其他配置文件。 –
不知道你是如何在dropwizard中做到這一點的,但是假設你有目錄映射器,在那裏你保存了所有的mapper.xml,對於SqlSessionFactoryBean你需要設置factory.setMapperLocations(「classpath:/ mapper」);在你的配置中沒有你說的地方mapper.xml位於(要搜索) –