小伙伴们,你们好!我正在为 wonlex kt24 申请。有 android 4.4,即 kit kat 🍫,为此安装了旧版本(0.63),其中仍然支持旧 SDK。在模拟器上,启动了最启动的项目,但在时钟上它甚至没有启动,尽管正在安装 apk。在哪里挖?
更改targetSdkVersion
为 19 也无济于事。
小伙伴们,你们好!我正在为 wonlex kt24 申请。有 android 4.4,即 kit kat 🍫,为此安装了旧版本(0.63),其中仍然支持旧 SDK。在模拟器上,启动了最启动的项目,但在时钟上它甚至没有启动,尽管正在安装 apk。在哪里挖?
更改targetSdkVersion
为 19 也无济于事。
this.tiles.map((x) => [x]).filter(x => x !== deletedTile) = reopenTile;
我尝试这样,但在过滤器块中它说:
赋值表达式的左侧必须是变量或属性访问。
我尝试这样:
this.tiles[this.tiles.map((x) => [x]).filter(x => x !== deletedTile)] = reopenTile;
但它给出了:
类型 'TileData[][]' 不能用作索引类型。
我想替换deletedTile
为reopenTile
. 怎么了?
PS基于此解决方案:
var items = Array(523, 3452, 334, 31, 5346);
items[items.map((e, i) => [i, e]).filter(e => e[1] == 3452)[0][0]] = 1010
我正在着陆。 https://merrymaker14.github.io/portfolio
但是 Font Awesome 中的图标不能用作链接。
<!-- Font Awesome -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
...
<div class="media">
<ul>
<li>
<a target="_blank" class="btn btn-social-icon btn-vk" href="https://vk.com/merrymaker14">
<span class="fa fa-vk"></span>
</a>
</li>
...
</ul>
</div>
为什么?该示例在链接中。
我想制作一个常规的进度条,但它不起作用。
应用程序.tsx:
const [progress, setProgress] = useState(0);
...
useEffect(() => {
setInterval(() => {
setProgress(progress + 1)
}, 1000);
}
});
...
return (
...
<ProgressBar progress={progress} />
...
)
进度条.tsx:
import React, {useEffect} from "react";
import { View, Animated } from "react-native";
type ProgressBarProps = {
progress: number
}
const ProgressBar: React.FC<ProgressBarProps> = (props) => {
const animation = new Animated.Value(props.progress);
useEffect(() => {
Animated.timing(animation, {
toValue: props.progress,
duration: 500
}).start();
console.log(props.progress)
});
return (
<View style={{ flex: 1, borderColor: "red", borderWidth: 2, borderRadius: 4}}>
<Animated.View
style={{
width: animation.interpolate({
inputRange: [0, 1],
outputRange: ["0%", "100%"],
extrapolate: "clamp"
}),
height: '10px',
backgroundColor: 'red'
}}
/>
</View>
);
};
export default ProgressBar;
结果,页面上只显示了一条红色的短线。 https://codesandbox.io/s/github/merrymaker14/react-native-web-example-as-testtask
type pictureType = {
portrait: string,
landscape: string
}
const picture: pictureType = {
portrait: require('./img/nc_ss19_620x960px_1.png'),
landscape: require('./img/960x576_1.png')
};
const [orientation, setOrientation] = useState('');
setOrientation('portrait') // Например
...
<Image source={picture[orientation]} />
元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“图片类型”。
如何正确描述类型?尝试了不同的方法。
在 App.js 中
<Route exact path='/page/:id' component={Dashboard} />
在 Dashboard.js 中,我可以获取 id,但是如何在不每次都编写的情况下进一步获取它?
仪表板.js:
import React, { Component } from 'react'
import PokemonList from '../pokemon/PokemonList'
export default class Dashboard extends Component {
render() {
const id = this.props.match.params.id;
return (
<div >
<PokemonList id={id} />
</div>
)
}
}
有没有更好的办法?然后我也必须继续转发它。
无法在渲染中操作数据,这很奇怪。
编码:
class Pagination extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
console.log(this.props);
const { id, count } = this.props;
let pages;
if (count != 0) {
pages = Math.ceil(count / 12);
}
}
render () {
console.log(this.pages); // undefined, в componentDidMount все нормально
...
我错过了什么?
$session = DB::table('test_sessions')
->select('id as session_id')
->where('test_sessions.test_id', '=', $request->get('test_id'))
->where('test_sessions.user_id', '=', Auth::user()->id)
->whereDate('test_sessions.end_at', '>=', Carbon::now('Europe/Moscow')) // Условие не отрабатывает.
->get();
即使 end_at 时间已经过期,我仍然会收到该条目。如果替换Carbon::now('Europe/Moscow')
为NOW()
,结果相同。
end_at - 类型字段datetime
;
使用 this.date = 'June 6, 2019' 格式变量,一切正常,但我需要一个特定的时间 + 15 分钟。键入Date.now()
(添加 15 分钟),然后对其进行处理,但将字符串值更改为,例如,new Date().toDateString()
我在输出中得到一组 NaN。如何解决?
我有一个项目,我是使用 akella 的教程完成的:https ://github.com/merrymaker14/vuegl 我决定将它上传到 GitHub Pages。 https://merrymaker14.github.io/vuegl
但他通常不会浏览页面,尽管他似乎已经设置了所有内容。为什么?
nuxt.config.js:
import pkg from './package'
/* nuxt.config.js */
// only add `router.base = '/<repository-name>/'` if `DEPLOY_ENV` is `GH_PAGES`
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
router: {
base: '/vuegl/'
}
} : {}
export default {
mode: 'universal',
/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: pkg.description }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
...routerBase,
router: {
middleware: 'pages',
//base: '/examples/vuegl/'
},
/*
** Global CSS
*/
css: [
],
/*
** Plugins to load before mounting the App
*/
plugins: [
],
/*
** Nuxt.js modules
*/
modules: [
],
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
}
}
}
有一个代码:
var coinsProfit = {
"etf_china": {
"plus": 100,
"minus": -50
},
"red_etf_china": {
"plus": 100,
"minus": -50
},
"etf_america": {
"plus": 100,
"minus": -40
},
"red_etf_america": {
"plus": 100,
"minus": -40
},
"bitcoin": {
"plus": 2000,
"minus": -30
},
"red_bitcoin": {
"plus": 2000,
"minus": -30
},
"dollar": {
"plus": 60,
"minus": -200
},
"red_dollar": {
"plus": 60,
"minus": -200
},
"eu": {
"plus": 80,
"minus": -40
},
"red_eu": {
"plus": 80,
"minus": -40
},
"gbr": {
"plus": 555,
"minus": -20
},
"red_gbr": {
"plus": 555,
"minus": -20
},
"rub": {
"plus": 666,
"minus": -50
},
"red_rub": {
"plus": 666,
"minus": -50
},
"yen": {
"plus": 222,
"minus": -30
},
"red_yen": {
"plus": 222,
"minus": -30
},
"etf_gold": {
"plus": 777,
"minus": -35
},
"red_etf_gold": {
"plus": 777,
"minus": -35
},
"etf_IT": {
"plus": 888,
"minus": -11
},
"red_etf_IT": {
"plus": 888,
"minus": -11
},
"etf_usa": {
"plus": 73,
"minus": -88
},
"red_etf_usa": {
"plus": 73,
"minus": -88
},
"etf_japan": {
"plus": 200,
"minus": -98
},
"red_etf_japan": {
"plus": 200,
"minus": -98
}
};
var coinsDataList = Object.keys(this.coinsProfit);
function plus(coinRandom) {
getEquelsCoin(coinRandom);
};
function minus(coinRandom) {
getEquelsCoin(coinRandom, 'minus');
};
function getEquelsCoin(coinRandom, sign = 'plus') {
for (var key in coinsProfit) {
if (key == coinRandom) {
coinsProfit[key].plus;
if (sign == 'plus') {
return coinsProfit[key].plus;
} else {
return coinsProfit[key].minus;
}
}
}
};
let count = 0;
coinRandom = coinsDataList[Math.floor(Math.random() * coinsDataList.length)];
count += plus(coinRandom);
UPD:如果您写入函数
console.log(coinsProfit[coinRandom].plus);
return coinsProfit[coinRandom].plus;
然后显示一个数字,但调用时的函数本身由于某种原因返回未定义。
有以下方法:
public void AddFocusEffect(AnimationClip focusClip, GameObject[] focusElements)
{
// AnimationClip focus = Resources.Load("Focus", typeof(AnimationClip)) as AnimationClip;
foreach (GameObject focusElement in focusElements)
{
focusElement.AddComponent<Outline>();
Animation anim = focusElement.AddComponent<Animation>();
anim.clip = focusClip;
}
}
focusClip 通过检查器挂起(因为注释掉的代码由于某种原因不起作用),结果,所有组件都正确创建,看起来好像我们自己添加和更正了它们,但不起作用(不像通常情况下)。
为什么会出现这种行为?
在控制器中有代码(Spring MVC)
@RequestMapping(value = "/books", method = RequestMethod.GET)
public String books(final HttpServletRequest request, final Model model) {
if (request.getParameter("name") || request.getParameter("publishing_house") || request.getParameter("the_year_of_publishing")) {
final List<Book> books = bookService.booksBySearch();
} else {
final List<Book> books = bookService.getAll();
}
model.addAttribute("books", books);
logger.debug("running in BookController.java -> books()");
logger.info(JSON.toJSON(request.getRequestURI()));
logger.info(JSON.toJSON(books));
return "/book/list.jsp";
}
结果,在编译时,我得到一个错误:
[错误] /C:/Users/Tim/eclipse-workspace/springMVC-mybatis-postgresql-fbcda0e11b1addcac43be8813e16b8b703022591/src/main/java/com/core/newbie/controller/BookController.java:[53,42] 错误的操作数类型二元运算符'||' 第一种类型:java.lang.String 第二种类型:java.lang.String
为什么以及如何解决?
JSP在场上用下划线发誓,但我没有找到任何信息表明这是不可能的。
Tomcat堆栈:
SEVERE: Servlet.service() for servlet [jsp] threw exception
javax.el.PropertyNotFoundException: Property [the_year_of_publishing] not found on type [com.core.newbie.model.Book]
...
21:50:32.693 [http-nio-8080-exec-5] DEBUG
org.springframework.web.servlet.DispatcherServlet - Could not complete request
org.apache.jasper.JasperException: An exception occurred processing [/WEB-
INF/book/showBook.jsp] at line [84]
81: <td><a href="#">${book.name}</a></td>
82: <td>${book.author}</td>
83: <td></td>
84: <td>${book.the_year_of_publishing}</td>
Book.java,部分代码:
public String getPublishingHouse() {
return publishing_house;
}
public void setPublishingHouse(final String publishing_house) {
this.publishing_house = publishing_house == null ? null : publishing_house.trim();
}
public Integer getTheYearOfPublishing() {
return the_year_of_publishing;
}
public void setTheYearOfPublishing(final Integer the_year_of_publishing) {
this.the_year_of_publishing = the_year_of_publishing;
}
在这两个领域发誓在 JSP 中,删除了一个。有什么问题?
我得到一个类似的 JSON 数组:
[com.core.newbie.controller.UserController](信息来自):[{"age":24,"id":1,"password":"001","userName":"001"},{"age":24,"id":2,"password":"002","userName":"002"},{"age":24,"id":3,"password":"002","userName":"002"},{"age":24,"id":4,"password":"004","userName":"004"},{"age":24,"id":5,"password":"005","userName":"005"},{"age":14,"id":111,"password":"12","userName":"derrick-2"}]
UserController,右侧代码:
@RequestMapping("/users")
public String users(final Model model) {
final List<User> users = userService.getAll();
model.addAttribute("users", users);
logger.debug("running in UserController.java -> users()");
logger.info(JSON.toJSON(users));
return "/user/users.jsp";
}
我正在尝试在 users.jsp 中显示它:
Пользователи:
=<c:forEach begin="0" end="${users.length() -1}" var="user" items="${users}">
<div>
${user.userName}
</div>
<br />
</c:forEach>
但它不输出。
$(users) 输出:
[com.core.newbie.model.User@5fc33319, com.core.newbie.model.User@6a8d7cfc, com.core.newbie.model.User@708bb2c2, com.core.newbie.model.User@500e9d80, com.core.newbie.model.User@16133763, com.core.newbie.model.User@1778c3c1]
同时,在通常的 User (1) 的情况下,一切都正确显示,来自 UserController 的代码:
@RequestMapping("/showUser")
public String showUser(final HttpServletRequest request, final Model model)
{
final int userId = Integer.parseInt(request.getParameter("id"));
final User user = userService.getUserById(userId);
model.addAttribute("user", user);
logger.debug("running in UserController.java -> showUser()");
logger.info(JSON.toJSON(request.getRequestURI()));
logger.info(JSON.toJSON(user));
return "/user/showUser.jsp";
}
UPD:UserServiceImpl.java,获取列表的一部分:
@Override
@Select("select * from n_user")
public List<User> getAll() {
return userMapper.findAll();
}
UPD2:编辑后代码变成了这样:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Пользователи</title>
</head>
<body>
Пользователи:
<c:forEach var="user" items="${users}">
<div>
<c:out value="${user.userName}" />
</div>
<br />
</c:forEach>
</body>
</html>
页面上仅显示“用户:”一词。${user.id} 和 ${user} 都不会在循环中输出任何内容。
无法使用 .从表中正确获取所有记录MyBatis
。
错误跟踪:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Tim/eclipse-workspace/springMVC-mybatis-postgresql-fbcda0e11b1addcac43be8813e16b8b703022591/src/main/java/com/core/newbie/controller/UserController.java:[49,52] incompatible types: com.core.newbie.model.User cannot be converted to java.util.List<com.core.newbie.model.User>
[ERROR] /C:/Users/Tim/eclipse-workspace/springMVC-mybatis-postgresql-fbcda0e11b1addcac43be8813e16b8b703022591/src/main/java/com/core/newbie/impl/UserServiceImpl.java:[29,8] com.core.newbie.impl.UserServiceImpl is not abstract and does not override abstract method getAll() in com.core.newbie.service.UserService
[ERROR] /C:/Users/Tim/eclipse-workspace/springMVC-mybatis-postgresql-fbcda0e11b1addcac43be8813e16b8b703022591/src/main/java/com/core/newbie/impl/UserServiceImpl.java:[59,23] getAll() in com.core.newbie.impl.UserServiceImpl cannot implement getAll() in com.core.newbie.service.UserService
return type java.util.List<com.core.newbie.model.User> is not compatible with com.core.newbie.model.User
[ERROR] /C:/Users/Tim/eclipse-workspace/springMVC-mybatis-postgresql-fbcda0e11b1addcac43be8813e16b8b703022591/src/main/java/com/core/newbie/impl/UserServiceImpl.java:[57,5] method does not override or implement a method from a supertype
[ERROR] /C:/Users/Tim/eclipse-workspace/springMVC-mybatis-postgresql-fbcda0e11b1addcac43be8813e16b8b703022591/src/main/java/com/core/newbie/impl/UserServiceImpl.java:[60,26] cannot find symbol
symbol: method findAll()
location: variable userMapper of type com.core.newbie.mapper.UserMapper
[INFO] 5 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
用户映射器.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.core.newbie.mapper.UserMapper">
<resultMap id="BaseResultMap" type="com.core.newbie.model.User">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="user_name" property="userName" jdbcType="VARCHAR"/>
<result column="password" property="password" jdbcType="VARCHAR"/>
<result column="age" property="age" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id, user_name, password, age
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from n_user
where id = #{id,jdbcType=INTEGER}
</select>
<select id="findAll" resultMap="BaseResultMap">
select * from n_user
</select>
<!--<select id="selectAllWithPagination" resultMap="BaseResultMap">
select * from n_user
</select>-->
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from n_user
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.core.newbie.model.User">
insert into n_user (id, user_name, password,
age)
values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{age,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.core.newbie.model.User">
insert into n_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="userName != null">
user_name,
</if>
<if test="password != null">
password,
</if>
<if test="age != null">
age,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="userName != null">
#{userName,jdbcType=VARCHAR},
</if>
<if test="password != null">
#{password,jdbcType=VARCHAR},
</if>
<if test="age != null">
#{age,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.core.newbie.model.User">
update n_user
<set>
<if test="userName != null">
user_name = #{userName,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
<if test="age != null">
age = #{age,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.core.newbie.model.User">
update n_user
set user_name = #{userName,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
age = #{age,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
用户.java(模型):
package com.core.newbie.model;
import javax.persistence.*;
import java.util.Set;
public class User {
private Integer id;
private String userName;
private String password;
private Integer age;
@ManyToMany
@JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> roles;
public Integer getId() {
return id;
}
public void setId(final Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(final String userName) {
this.userName = userName == null ? null : userName.trim();
}
public String getPassword() {
return password;
}
public void setPassword(final String password) {
this.password = password == null ? null : password.trim();
}
public Integer getAge() {
return age;
}
public void setAge(final Integer age) {
this.age = age;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
用户服务:
package com.core.newbie.service;
import com.core.newbie.model.User;
public interface UserService {
User getUserById(int userId);
// User findByUsername(String username);
void insetUser(User user);
User getAll();
}
UserServiceImpl.java:
package com.core.newbie.impl;
import com.core.newbie.mapper.UserMapper;
import com.core.newbie.model.User;
import com.core.newbie.service.UserService;
import java.util.List;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User getUserById(final int userId) {
return userMapper.selectByPrimaryKey(userId);
}
@Override
public void insetUser(final User user) {
userMapper.insert(user);
}
@Override
@Select("select * from n_user")
public List<User> getAll() {
return userMapper.findAll();
}
}
用户控制器.java:
package com.core.newbie.controller;
import com.alibaba.fastjson.JSON;
import com.core.newbie.model.User;
import com.core.newbie.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("/user")
public class UserController {
Logger logger = Logger.getLogger(UserController.class);
@Autowired
private UserService userService;
@RequestMapping("/showUser")
public String showUser(final HttpServletRequest request, final Model model)
{
final int userId = Integer.parseInt(request.getParameter("id"));
final User user = userService.getUserById(userId);
model.addAttribute("user", user);
logger.debug("running in UserController.java -> showUser()");
logger.info(JSON.toJSON(request.getRequestURI()));
logger.info(JSON.toJSON(user));
return "/user/showUser.jsp";
}
@RequestMapping("/users")
public String users() {
final List<User> users = userService.getAll();
logger.debug("running in UserController.java -> users()");
logger.info(JSON.toJSON(users));
return "/user/users.jsp";
}
}
如何在 Spring 中分离角色?例如,如果管理员(来自数据库的值)为 true,则在 jsp 中打开一个特定链接以供查看,并且对其他用户(与其他角色)。
这是通过 Spring Security 完成的,对吧?
UPD:欢迎任何建议。有人加减号,请在评论中退订。
出现上述错误。
测试本身:
// Copyright (c) 1998-2016 Core Solutions Limited. All rights reserved.
//
============================================================================
// CURRENT VERSION CNT.5.0.1
//
============================================================================
// CHANGE LOG
// CNT.5.0.1 : 2016-08-26, derrick.liang, creation
//
============================================================================
package com.core.newbie.action;
import com.alibaba.fastjson.JSON;
import com.core.newbie.model.User;
import com.core.newbie.service.UserService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-mybatis.xml"})
public class UserActionTest {
private static final Logger logger = Logger.getLogger(UserActionTest.class);
private UserService userService;
@Autowired
public void setUserService(final UserService userService) {
this.userService = userService;
}
public UserService getUserService() {
return userService;
}
@Test
public void test1() {
final User user = userService.getUserById(1);
logger.info(JSON.toJSON(user));
}
@Test
public void test2() {
final User user = new User();
user.setId(111);
user.setAge(14);
user.setPassword("12");
user.setUserName("derrick-2");
userService.insetUser(user);
logger.info(JSON.toJSON(user));
}
}
spring-mybatis.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"
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">
<!-- 自动扫描 -->
<context:component-scan base-package="com.core.newbie"/>
<!-- 引入配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}"/>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${maxActive}"/>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${maxIdle}"/>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}"/>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}"/>
</bean>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:mapping/*.xml"/>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.core.newbie.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
痕迹:
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 6.063 sec
<<< FAILURE!
test1(com.core.newbie.action.UserActionTest) Time elapsed: 2.455 sec <<<
ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:319)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.springframework.beans.factory.BeanInitializationException:
Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [jdbc.properties] cannot be opened because it does not exist
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:121)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 31 more
Caused by: java.io.FileNotFoundException: class path resource
[jdbc.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80)
... 41 more
test2(com.core.newbie.action.UserActionTest) Time elapsed: 0.465 sec <<<
ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:319)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.springframework.beans.factory.BeanInitializationException:
Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [jdbc.properties] cannot be opened because it does not exist
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:121)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 31 more
Caused by: java.io.FileNotFoundException: class path resource
[jdbc.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80)
... 41 more
Results :
Tests in error:
test1(com.core.newbie.action.UserActionTest): Failed to load ApplicationContext
test2(com.core.newbie.action.UserActionTest): Failed to load ApplicationContext
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
安装Maven的时候报错No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
,甚至创建了环境变量。IDE:用于 EE 的 Eclipse。
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>growthing-02</groupId>
<artifactId>growthing-02</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>growthing-02 Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<!--spring version-->
<spring.version>4.0.2.RELEASE</spring.version>
<!--mybatis version-->
<mybatis.version>3.2.6</mybatis.version>
<!--log4j version-->
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<dependencies>
<!--<dependency>-->
<!--<groupId>junit</groupId>-->
<!--<artifactId>junit</artifactId>-->
<!--<version>4.12</version>-->
<!--<!–This means it will be loaded only under development–>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--spring core jars-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<!--<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!--mybatis core jars-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!--spring-mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<!--java ee-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<!--postgresql db-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
</dependency>
<!--dbcp jar, using for configuring db information in applicationContext.xml-->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!--JSTL tag jar-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--log-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!--format log-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!--jason-->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<!--<finalName>main</finalName>-->
<plugins>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-compiler-plugin</artifactId>-->
<!--<configuration>-->
<!--<source>1.7</source>-->
<!--<target>1.7</target>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>main</warName>
<outputDirectory>D:\apache-tomcat-8.5.11\webapps</outputDirectory>
</configuration>
</plugin>
</plugins>
<!--<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>-->
</build>
我什至指出
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.9</source>
<target>1.9</target>
</configuration>
</plugin>
结果相同。