我在 Java/Spring/ Apache Cxf 上工作网络应用程序,突然间,当我进行了一些明显幼稚的更改时出现错误,
25-Aug-2017 11:48:43.036 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
25-Aug-2017 11:48:43.540 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
25-Aug-2017 11:48:43.554 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
[2017-08-25 11:48:43,586] Artifact jaxrs-tutorials:war exploded: Error during artifact deployment. See server log for details.
25-Aug-2017 11:48:49.258 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Applications/Tomcat-8.5.16/webapps/manager]
25-Aug-2017 11:48:49.310 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Applications/Tomcat-8.5.16/webapps/manager] has finished in [51] ms
info的错误,25-Aug-2017 11:48:43.540 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
25-Aug-2017 11:48:43.554 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors

config目录用于 Java annotation based config下面提供了代码。AppConfig文件,@Configuration
@ComponentScan(AppConfig.SERVICE_PACKAGE)
public class AppConfig {
public static final String BASE_PACKAGE = "mobi.puut";
public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".services";
private static final String RESOURCES_PACKAGE = BASE_PACKAGE + ".rest";
private static final String PROVIDER_PACKAGE = BASE_PACKAGE + ".rest.provider";
public static final String API_BASE = "/api/*";
@ApplicationPath("/")
public class JaxRsApiApplication extends Application {
}
@Bean(destroyMethod = "shutdown")
public SpringBus cxf() {
return new SpringBus();
}
@Bean
@DependsOn("cxf")
public Server jaxRsServer(ApplicationContext appContext) {
JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
factory.setServiceBeans(restServiceList(appContext));
factory.setAddress("/" + factory.getAddress());
factory.setProviders(restProviderList(appContext, jsonProvider()));
return factory.create();
}
@Bean
public JaxRsApiApplication jaxRsApiApplication() {
return new JaxRsApiApplication();
}
@Bean
public JacksonJsonProvider jsonProvider() {
return new JacksonJsonProvider();
}
private List<Object> restServiceList(ApplicationContext appContext) {
return RestServiceBeanScanner.scan(appContext, AppConfig.RESOURCES_PACKAGE);
}
private List<Object> restProviderList(final ApplicationContext appContext,
final JacksonJsonProvider jsonProvider) {
final List<Object> providers = RestProviderBeanScanner.scan(appContext, PROVIDER_PACKAGE);
providers.add(jsonProvider);
return providers;
}
}
WebInitializer提供,public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.addListener(new ContextLoaderListener(createWebAppContext()));
addApacheCxfServlet(servletContext);
}
private void addApacheCxfServlet(ServletContext servletContext) {
CXFServlet cxfServlet = new CXFServlet();
ServletRegistration.Dynamic appServlet = servletContext.addServlet("CXFServlet", cxfServlet);
appServlet.setLoadOnStartup(1);
Set<String> mappingConflicts = appServlet.addMapping(AppConfig.API_BASE);
}
private WebApplicationContext createWebAppContext() {
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.register(AppConfig.class);
return appContext;
}
}
logger获取更多信息以及我应该在哪里使用它们?此外,任何有关解决问题的见解都会有所帮助。我已经更新了 JAR带有 mvn clean install 的文件和 mvn idea:idea命令。UPDATETomcat Localhost Log
Tomcat Catalina Log
最佳答案
我想写一个关于这个问题的详细答案以及我解决问题所遵循的步骤。
A. 没有足够的日志信息。我查了一下POM并找到了这个,
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
SLF4J我刚刚删除了排除 XML 标记以获取更多日志信息。于是,就变成这样了 <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userService' for bean class [mobi.puut.services.UserServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [mobi.puut.services.UserService2Impl]
ConflictingBeanDefinitionException用于创建具有相同名称的 bean。虽然我对 Spring 有一些经验,我需要用 Apache Cxf 创建一个项目因此,为此目的克隆一个演示项目。他们有一个相同的实体 User和相同 definition - interface和相同 implementation其中。虽然我有 refactored对于项目中的所有类并且似乎没有明显错误,我仍然有一个问题 - 我保留相同的 bean 名称 "userService在接口(interface)的 2 个实现中。User2实体中的类,public class User2 {
private Integer id;
private String name;
public User2() {
}
public User2(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return String.format("{id=%s,name=%s}", id, name);
}
}
User实体中的类,@Entity
@Table(name = "users")
public class User {
@Id
@Column
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@NotNull
@Column(name = "name")
@Size(min = 5, max = 45, message = "Name must be between 5 and 45 characters.")
private String name;
public User() {
}
public User(int id, String name) {
super();
this.id = id;
this.name = name;
}
public User(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User)) return false;
User user = (User) o;
if (getId() != user.getId()) return false;
return getName().equals(user.getName());
}
@Override
public int hashCode() {
int result = getId();
result = 31 * result + getName().hashCode();
return result;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
services中的接口(interface)目录,public interface IUserService2 {
Collection<User2> getUsers();
User2 getUser(Integer id);
Response add(User2 user);
}
public interface IUserService {
List<User> getCurrentStatuses();
void create(User user);
List<User> getAllUsers();
}
services内部接口(interface)的实现指示,@Service("userService")
public class UserService2Impl implements IUserService2 {
private static Map<Integer, User2> users = new HashMap<Integer, User2>();
static {
users.put(1, new User2(1, "foo"));
users.put(2, new User2(2, "bar"));
users.put(3, new User2(3, "baz"));
}
public UserService2Impl() {
}
@Override
public Collection<User2> getUsers() {
return users.values();
}
@Override
public User2 getUser(Integer id) {
return users.get(id);
}
@Override
public Response add(User2 user) {
user.setId(users.size()+1);
users.put(user.getId(), user);
//do more stuff to add user to the system..
return Response.status(Response.Status.OK).build();
}
}
@Service("userService")
public class UserServiceImpl implements IUserService {
@Autowired
@Qualifier("userDao")
public IUserDao userDao;
public List<User> getCurrentStatuses() {
return userDao.getAllUsers();
}
public void create(User user) {
userDao.saveOrUpdate(user);
}
public List<User> getAllUsers() {
List<User> users = userDao.getAllUsers();
if (Objects.isNull(users)) {
return null;
}
return users;
}
}
error - 我注释了 2 个具有相同 bean 名称的类 "userService" .我不得不像这样改变它来为 bean 提供一个不同的名称,@Service("user2Service")
public class UserService2Impl implements IUserService2 {
// some code
}
ConflictingBeanDefinitionException由于 2 个 bean 同名,我只需要提供不同的名称。org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'mobi.puut.database.IUserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userDao)}
// some consequent error messages not necessay to solve the issue
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'mobi.puut.database.IUserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userDao)}
UnsatisfiedDependencyException并说它无法创建名称为 userService 的 bean .好的,这是我拥有并集成到项目中的代码。通过字段表示的 Unsatisfied 依赖,即 userDao . userDao是IUserDao的接口(interface)实例它是 @autowired像这样, @Autowired
public IUserDao userDao;
@Service("userService")
public class UserServiceImpl implements IUserService {
@Autowired
public IUserDao userDao;
public List<User> getCurrentStatuses() {
return userDao.getAllUsers();
}
public void create(User user) {
userDao.saveOrUpdate(user);
}
public List<User> getAllUsers() {
List<User> users = userDao.getAllUsers();
if (Objects.isNull(users)) {
return null;
}
return users;
}
}
database 中有一个接口(interface)目录和随后为用户实现的界面。接口(interface)名称是 IUserDao看起来soemthing like this,
public interface IUserDao {
boolean create(User user);
void saveOrUpdate(User user);
boolean create(List<User> users);
List<User> getAllUsers();
User getById(int id);
}
@Repository("userDao")
public class UserDaoImpl implements IUserDao {
@Autowired
private SessionFactory sessionFactory;
// the HQL queries
}
NoSuchBeanDefinitionException并且应用程序没有找到 IUserDao 类型(类)的合格 bean .我有所有 HQL查询在执行IUserDao并且代码之前完美运行。database层是 NOT集成到应用程序中。这是configuration我用了,public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.addListener(new ContextLoaderListener(createWebAppContext()));
addApacheCxfServlet(servletContext);
}
private void addApacheCxfServlet(ServletContext servletContext) {
CXFServlet cxfServlet = new CXFServlet();
ServletRegistration.Dynamic appServlet = servletContext.addServlet("CXFServlet", cxfServlet);
appServlet.setLoadOnStartup(1);
Set<String> mappingConflicts = appServlet.addMapping(AppConfig.API_BASE);
}
private WebApplicationContext createWebAppContext() {
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
// register all the config classes here
appContext.register(AppConfig.class);
return appContext;
}
}
WebInitializer中集成了无数据库代码。 .我写了一个新类提供了database connection的所有信息和 hibernate integration看起来像,@Configuration
@EnableWebMvc
@EnableTransactionManagement
@ComponentScan(basePackages = {"mobi.puut.database"})
public class DatabaseConfig {
@Bean
public LocalSessionFactoryBean sessionFactory() {
// mobi.puut.entities
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(
new String[]{"mobi.puut.entities"});
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(
SessionFactory sessionFactory) {
HibernateTransactionManager txManager
= new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);
return txManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
// dataSource.setUrl("jdbc:mysql://localhost:3306/wallet?createDatabaseIfNotExist=true");
dataSource.setUrl("jdbc:mysql://localhost:3306/Wallet");
dataSource.setUsername("testuser");
dataSource.setPassword("testpassword");
return dataSource;
}
Properties hibernateProperties() {
Properties properties = new Properties();
// properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
return properties;
}
}
WebInitializer .这是我以前用的代码registered之前在 WebInitializer 中的配置,appContext.register(AppConfig.class);
appContext.register(AppConfig.class, DatabaseConfig.class);
config目录看起来像,
SUMMERYi. ConflictingBeanDefinitionException
ii. UnsatisfiedDependencyException
iii. NoSuchBeanDefinitionException
ConflictingBeanDefinitionException -> 2 个同名 bean UnsatisfiedDependencyException -> 有 bean (= "userDao")在不正确使用的类中NoSuchBeanDefinitionException -> 代码是正确的,但需要在配置中添加 datbase 层,所以 Spring IoC找到 bean 。关于java - org.apache.catalina.core.StandardContext.startInternal 一个或多个监听器启动失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45875230/
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
导读:随着叮咚买菜业务的发展,不同的业务场景对数据分析提出了不同的需求,他们希望引入一款实时OLAP数据库,构建一个灵活的多维实时查询和分析的平台,统一数据的接入和查询方案,解决各业务线对数据高效实时查询和精细化运营的需求。经过调研选型,最终引入ApacheDoris作为最终的OLAP分析引擎,Doris作为核心的OLAP引擎支持复杂地分析操作、提供多维的数据视图,在叮咚买菜数十个业务场景中广泛应用。作者|叮咚买菜资深数据工程师韩青叮咚买菜创立于2017年5月,是一家专注美好食物的创业公司。叮咚买菜专注吃的事业,为满足更多人“想吃什么”而努力,通过美好食材的供应、美好滋味的开发以及美食品牌的孵
这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候
遍历文件夹我们通常是使用递归进行操作,这种方式比较简单,也比较容易理解。本文为大家介绍另一种不使用递归的方式,由于没有使用递归,只用到了循环和集合,所以效率更高一些!一、使用递归遍历文件夹整体思路1、使用File封装初始目录,2、打印这个目录3、获取这个目录下所有的子文件和子目录的数组。4、遍历这个数组,取出每个File对象4-1、如果File是否是一个文件,打印4-2、否则就是一个目录,递归调用代码实现publicclassSearchFile{publicstaticvoidmain(String[]args){//初始目录Filedir=newFile("d:/Dev");Datebeg